14 Replies - 702 Views - Last Post: 15 April 2012 - 06:13 PM Rate Topic: -----

#1 IsoChronous  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 29-June 11

conflict between strftime and strlen

Posted 14 April 2012 - 11:12 AM

My teacher gave me a challenge two weeks ago to make a time clock program for the class to use. Im pretty proud of what i have so far, but ive hit a snag. Any good time clock program needs to display the date and time. for awhile, i couldnt get the program to display anything other than 24 hour time, until today. I finally got it to work, but now a new problem has arisen. each person in my class has an ID number that is 6 numbers. I made my program to accept only 6 numbers, however now it wont accept amount of numbers i enter.
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <conio.h>
#include <sstream>
#include <fstream>
#include <ctime>
#include <stdlib.h>

using namespace std;

int StringToNumber(string MyString)
{
    istringstream converter(MyString);
    int result;

    converter >> result;
    return result;
}

class Student
{
    public:
        string FirstName;
        string LastName;
        string time;
        char ID;
        char ch;
        Student(string afirstname, string alastname, string atime, char aid) :
        FirstName(afirstname), LastName(alastname), time(atime),
        ID(aid) {}
};

class EnterName : public Student
{
    public:
        enum EnterNameType {};
        EnterNameType Type;
        EnterName(string afirstname, string alastname, EnterNameType atype, string atime,
        char aid) : Type(atype),
        Student(afirstname, alastname, atime, aid) {}
};

class EnterID
{
    public:
        Student *GetStudentFirstName(string FirstName);
        Student *GetStudentLastName(string LastName);
};

class EnterPassword : public EnterID
{
    public:
        EnterID *GetStudentID(char ID);
};

string EnterOnlyNumbers()
{
    const char BACKSPACE = '\b';
    const char RETURN = '\r';
    string numAsString = "";
    char ch = getch();

    while (ch != RETURN)
    {
        if (ch >= '0' && ch <= '9')
        {
            cout << '*';
            numAsString += ch;
        }

        else if (ch == BACKSPACE)
    {
            if (numAsString.length() != 0)
        {
            cout << "\b \b";
            numAsString.resize(numAsString.length() - 1);
        }
    }
        ch = getch();
    }
    return numAsString;
}

int main()
{
        time_t rawtime;
        struct tm * timeinfo;
        char buffer [80];       //The first 5 lines are what i added today to make the time work. 
        time ( &rawtime );      //Where is says "char buffer [80]" is where the problem is i think.
        timeinfo = localtime ( &rawtime );
        string FirstName;
        string LastName;
        char ID[7];             //I think its conflicting with "char ID[7]".
        bool done = false;

        do {
        strftime(buffer,80,"The current date and time is %I:%M%p %A, %B %d %Y.\n",timeinfo);
        puts (buffer);
        cout << "Please enter your name:\n" << endl;
        cin >> FirstName >> LastName;

        if ((FirstName == "Ryan" && LastName == "Batson"))
        {
            cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
            string entered = EnterOnlyNumbers();
            fgets(ID, sizeof(ID), stdin);
            if( ID[strlen(ID) - 1] == 7)  //This is where the problem occurs. Any amount of numbers i enter is rejected.
            {
                cout << "\nYou have successfully clocked in.\n" << endl;
            }

            else if( ID[strlen(ID) - 1] != 7)
            {
                cout << "\nPlease enter your 6 digit ID.\n" << endl;
            }

            ofstream myfile;
            ostringstream filename;
            filename << LastName << ", " << FirstName << ".txt";
            myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
            {
                myfile << FirstName << " " << LastName << "\n";
                myfile << ctime(&rawtime) << endl;
                myfile.close();
            }
        }

        if ((FirstName == "Adrien" && LastName == "Walls"))
        {
            cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
            string entered = EnterOnlyNumbers();
            fgets(ID, sizeof(ID), stdin);
            if( ID[strlen(ID) - 1] == 7)
            {
                cout << "\nYou have successfully clocked in.\n" << endl;
            }

            else if( ID[strlen(ID) != 7])
            {
                cout << "\nPlease enter your 6 digit ID.\n" << endl;
            }

            ofstream myfile;
            ostringstream filename;
            filename << LastName << ", " << FirstName << ".txt";
            myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
            {
                myfile << FirstName << " " << LastName << "\n";
                myfile << ctime(&rawtime) << endl;
                myfile.close();
            }
        }

        if ((FirstName == "Philip" && LastName == "Anderson"))
        {
            cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
            string entered = EnterOnlyNumbers();
            fgets(ID, sizeof(ID), stdin);
            if( ID[strlen(ID) - 1] == 7)
            {
                cout << "\nYou have successfully clocked in.\n" << endl;
            }

            else if( ID[strlen(ID) != 7])
            {
                cout << "\nPlease enter your 6 digit ID.\n" << endl;
            }

            ofstream myfile;
            ostringstream filename;
            filename << LastName << ", " << FirstName << ".txt";
            myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
            {
                myfile << FirstName << " " << LastName << "\n";
                myfile << ctime(&rawtime) << endl;
                myfile.close();
            }
        }

        if ((FirstName == "Jordan" && LastName == "Bergeria"))
        {
            cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
            string entered = EnterOnlyNumbers();
            fgets(ID, sizeof(ID), stdin);
            if( ID[strlen(ID) - 1] == 7)
            {
                cout << "\nYou have successfully clocked in.\n" << endl;
            }

            else if( ID[strlen(ID) != 7])
            {
                cout << "\nPlease enter your 6 digit ID.\n" << endl;
            }

            ofstream myfile;
            ostringstream filename;
            filename << LastName << ", " << FirstName << ".txt";
            myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
            {
                myfile << FirstName << " " << LastName << "\n";
                myfile << ctime(&rawtime) << endl;
                myfile.close();
            }
        }

        if ((FirstName == "Neil" && LastName == "Dawes"))
        {
            cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
            string entered = EnterOnlyNumbers();
            fgets(ID, sizeof(ID), stdin);
            if( ID[strlen(ID) - 1] == 7)
            {
                cout << "\nYou have successfully clocked in.\n" << endl;
            }

            else if( ID[strlen(ID) != 7])
            {
                cout << "\nPlease enter your 6 digit ID.\n" << endl;
            }

            ofstream myfile;
            ostringstream filename;
            filename << LastName << ", " << FirstName << ".txt";
            myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
            {
                myfile << FirstName << " " << LastName << "\n";
                myfile << ctime(&rawtime) << endl;
                myfile.close();
            }
        }

        if ((FirstName == "Erik" && LastName == "Baumgarten"))
        {
            cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
            string entered = EnterOnlyNumbers();
            fgets(ID, sizeof(ID), stdin);
            if( ID[strlen(ID) - 1] == 7)
            {
                cout << "\nYou have successfully clocked in.\n" << endl;
            }

            else if( ID[strlen(ID) != 7])
            {
                cout << "\nPlease enter your 6 digit ID.\n" << endl;
            }

            ofstream myfile;
            ostringstream filename;
            filename << LastName << ", " << FirstName << ".txt";
            myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
            {
                myfile << FirstName << " " << LastName << "\n";
                myfile << ctime(&rawtime) << endl;
                myfile.close();
            }
        }

        if ((FirstName == "Sean" && LastName == "Campbell"))
        {
            cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
            string entered = EnterOnlyNumbers();
            fgets(ID, sizeof(ID), stdin);
            if( ID[strlen(ID) - 1] == 7)
            {
                cout << "\nYou have successfully clocked in.\n" << endl;
            }

            else if( ID[strlen(ID) != 7])
            {
                cout << "\nPlease enter your 6 digit ID.\n" << endl;
            }

            ofstream myfile;
            ostringstream filename;
            filename << LastName << ", " << FirstName << ".txt";
            myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
            {
                myfile << FirstName << " " << LastName << "\n";
                myfile << ctime(&rawtime) << endl;
                myfile.close();
            }
        }

        if ((FirstName == "Sean-Thomas" && LastName == "Rowe"))
        {
            cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
            string entered = EnterOnlyNumbers();
            fgets(ID, sizeof(ID), stdin);
            if( ID[strlen(ID) - 1] == 7)
            {
                cout << "\nYou have successfully clocked in.\n" << endl;
            }

            else if( ID[strlen(ID) != 7])
            {
                cout << "\nPlease enter your 6 digit ID.\n" << endl;
            }

            ofstream myfile;
            ostringstream filename;
            filename << LastName << ", " << FirstName << ".txt";
            myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
            {
                myfile << FirstName << " " << LastName << "\n";
                myfile << ctime(&rawtime) << endl;
                myfile.close();
            }
        }

        if ((FirstName == "Cody" && LastName == "Elston"))
        {
            cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
            string entered = EnterOnlyNumbers();
            fgets(ID, sizeof(ID), stdin);
            if( ID[strlen(ID) - 1] == 7)
            {
                cout << "\nYou have successfully clocked in.\n" << endl;
            }

            else if( ID[strlen(ID) != 7])
            {
                cout << "\nPlease enter your 6 digit ID.\n" << endl;
            }

            ofstream myfile;
            ostringstream filename;
            filename << LastName << ", " << FirstName << ".txt";
            myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
            {
                myfile << FirstName << " " << LastName << "\n";
                myfile << ctime(&rawtime) << endl;
                myfile.close();
            }
        }

        if ((FirstName == "Scotty" && LastName == "Smith"))
        {
            cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
            string entered = EnterOnlyNumbers();
            fgets(ID, sizeof(ID), stdin);
            if( ID[strlen(ID) - 1] == 7)
            {
                cout << "\nYou have successfully clocked in.\n" << endl;
            }

            else if( ID[strlen(ID) != 7])
            {
                cout << "\nPlease enter your 6 digit ID.\n" << endl;
            }

            ofstream myfile;
            ostringstream filename;
            filename << LastName << ", " << FirstName << ".txt";
            myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
            {
                myfile << FirstName << " " << LastName << "\n";
                myfile << ctime(&rawtime) << endl;
                myfile.close();
            }
        }

            system("PAUSE");
            system("cls");

        } while (!done);

        return 0;
}


i should note that my class is not actually a programming class and i am teaching myself this on the side, so my code should be pretty rough around the edges (probably very rough). any advice is welcome.

Is This A Good Question/Topic? 0
  • +

Replies To: conflict between strftime and strlen

#2 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1621
  • View blog
  • Posts: 3,079
  • Joined: 30-May 10

Re: conflict between strftime and strlen

Posted 14 April 2012 - 11:36 AM

My first suggestion would be to create some more functions, to reduce the length of your main - which is rapidly heading for 300 lines long!
Was This Post Helpful? 0
  • +
  • -

#3 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 762
  • View blog
  • Posts: 2,214
  • Joined: 20-March 10

Re: conflict between strftime and strlen

Posted 14 April 2012 - 04:48 PM

Hi IsoChronous,


Well you do have a lot of problems...

But dealing with your question first....

consider this line of code

if( ID[strlen(ID) - 1] == 7)  //This is where the problem occurs. Any amount of numbers i enter is rejected.



In plain English this is saying ' If the char array 'ID's n-1th character is equal to 7
(bearing in mind its a char array and not an int array) then do something useful..'

If this is what you are indeed testing for i.e. that the n-1th character in the array is equal to 7

your probably wanting to do this

if( ID[strlen(ID) - 1] == '7')  



But I don't think your wanting to do that are you ?

In plain English what you mean I think is..

'If the string length of char array ID is equal to 6 then do something useful..'

if so consider this code

#include <iostream>
#include <cstdio>
#include <cstring>
#define MAXALLOWED 100
using namespace std;

int main()
{

    char ID[MAXALLOWED];

    cout << "Enter Your I.D." << endl;

    fgets(ID, sizeof(ID), stdin);

    if(strlen(ID)-1 == 4)  
    {
        cout << "\nYou have successfully clocked in.\n" << endl;
    }

    else if( strlen(ID)-1 != 4)
    {
        cout << "\nIncorrect Number of Digits.\n" << endl;
    }

    
    return 0;
}



Run this program and enter 1234
What result do you get ?

Why ?

Now change MAXALLOWED to 5

Build and Run
Enter 1234

What result do you get ?

Why ?

Best Wishes
Snoopy.

This post has been edited by snoopy11: 14 April 2012 - 05:21 PM

Was This Post Helpful? 0
  • +
  • -

#4 IsoChronous  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 29-June 11

Re: conflict between strftime and strlen

Posted 15 April 2012 - 10:50 AM

View PostSalem_c, on 14 April 2012 - 01:36 PM, said:

My first suggestion would be to create some more functions, to reduce the length of your main - which is rapidly heading for 300 lines long!

do you mean breaking down some of the variables in my int main() into more functions? I must say that teaching myself C++ is very hard. My only resource is a big "C++ for Dummies" book.

@snoopy11, yes, i want the string length to be equal to 6, not anything more or less. for the code you put up, i think what youre trying to show me is that in C++ (and some other programming languages, i am told), counting starts at zero, not at one. so that if i want to store 6 charaters in an array, i would enter "7" in the code. also, could you elaborate a little more on your code? im not quite understanding it. thanks for the help.
Was This Post Helpful? 0
  • +
  • -

#5 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1304
  • View blog
  • Posts: 4,488
  • Joined: 19-February 09

Re: conflict between strftime and strlen

Posted 15 April 2012 - 11:45 AM

View PostIsoChronous, on 15 April 2012 - 07:50 PM, said:

i want the string length to be equal to 6, not anything more or less.


if(strlen(ID) == 6)




Character Sequences


Basically, there are two types of strings. C type strings and C++ type strings.
Was This Post Helpful? 0
  • +
  • -

#6 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 762
  • View blog
  • Posts: 2,214
  • Joined: 20-March 10

Re: conflict between strftime and strlen

Posted 15 April 2012 - 01:33 PM

View PostIsoChronous, on 15 April 2012 - 05:50 PM, said:

@snoopy11, yes, i want the string length to be equal to 6, not anything more or less. for the code you put up, i think what youre trying to show me is that in C++ (and some other programming languages, i am told), counting starts at zero, not at one. so that if i want to store 6 charaters in an array, i would enter "7" in the code. also, could you elaborate a little more on your code? im not quite understanding it. thanks for the help.


Err Right,

No It wasn't what I was really trying to say obviously you
didn't build and run the program supplied.

Yes counting does start at zero not at one so...
an array of '7' like

char ID[7];

would be 8 characters long wouldn't it ?

01234567
12345678

see what I mean ?

also your using fgets which if your not careful can be confusing for newbies.

FGETS Reference please read.

at the top of the fgets reference it says

Quote

char * fgets ( char * str, int num, FILE * stream );

Get string from stream
Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or the End-of-File is reached, whichever comes first.


Notice I have underlined the num-1 bit for emphasis.

Is my code any clearer to you now ?

Try running it, it might help you understand what I'm trying to tell you.

@define

Yes if the OP was using cin (which I am getting to) your supplied code would be correct,
but the OP is using fgets so it should have been

if(strlen(ID)-1 == 6)



back to IsoChronous....

It may be wise for you to convert all your fgets statements to cin statements

cin Reference

Usage in your case would be

cin >> ID;


If you do persist with fgets which is entirely up to you then consider this ...

If you are going to go with fgets I strongly suggest you run this program this time.

#include <iostream>
#include <cstdio>
#include <cstring>
#define MAXALLOWED 6
using namespace std;

int main()
{

    char ID[MAXALLOWED];

    cout << "Enter Your I.D." << endl;

    fgets(ID, sizeof(ID), stdin);
    

    if(strlen(ID)-1 == 4)  //This is where the problem occurs. Any amount of numbers i enter is rejected.
    {
        cout << "\nYou have successfully clocked in.\n" << endl;
    }

    else if( strlen(ID)-1 != 4)
    {
        cout << "\nIncorrect Number of Digits.\n" << endl;
    }


    return 0;
}



Note the value of MAXALLOWED is set to 6 and I'm testing for strings of length = 4.
This is like saying char ID[6];

Build and run the program.

Enter 1234

What result do you get ?

Run the program again

Enter 123

What result do you get ?

Everything seem ok so far.. ?

Run the program again

Enter 123456789

What result do you get ?

Were you surprised ?

Why did it happen ?

Best wishes
Snoopy.

This post has been edited by snoopy11: 15 April 2012 - 01:36 PM

Was This Post Helpful? 0
  • +
  • -

#7 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1304
  • View blog
  • Posts: 4,488
  • Joined: 19-February 09

Re: conflict between strftime and strlen

Posted 15 April 2012 - 02:23 PM

Ahh, I must be getting silly with using C++.

Quote

A newline character makes fgets stop reading, but it is considered a valid character and therefore it is included in the string copied to str.

This post has been edited by #define: 15 April 2012 - 02:24 PM

Was This Post Helpful? 0
  • +
  • -

#8 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 275
  • View blog
  • Posts: 1,778
  • Joined: 20-September 08

Re: conflict between strftime and strlen

Posted 15 April 2012 - 02:38 PM

You really do need to recode from bottom up paying attention to what Salem said about using functions for each task

Also, you will do well to use C++ strings where ever possible, especially for input, and then to use getline( cin, lineStr ) to avoid 'new line char' problems.

It seems you could also use a file of valid names/ids... to check against at 'login' ...

So your program main loop seems something like this ...
do
{
   //Keep getting this name/id until a valid match in file occurs 
   //Get date/time string
   //append to file for this name/id the new date/time string
} while( more() );


Was This Post Helpful? 0
  • +
  • -

#9 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 762
  • View blog
  • Posts: 2,214
  • Joined: 20-March 10

Re: conflict between strftime and strlen

Posted 15 April 2012 - 03:34 PM

View Post#define, on 15 April 2012 - 09:23 PM, said:

Ahh, I must be getting silly with using C++.


Nah mate,

You're alright it was just a FYI type of thing...

Well you know I think you're a top programmer anyway so..

Best Wishes

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#10 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 762
  • View blog
  • Posts: 2,214
  • Joined: 20-March 10

Re: conflict between strftime and strlen

Posted 15 April 2012 - 03:47 PM

View PostDavid W, on 15 April 2012 - 09:38 PM, said:

You really do need to recode from bottom up paying attention to what Salem said about using functions for each task


Agreed...
No arguing with that.

View PostDavid W, on 15 April 2012 - 09:38 PM, said:

Also, you will do well to use C++ strings where ever possible, especially for input, and then to use getline( cin, lineStr ) to avoid 'new line char' problems.


Well the OP would probably be better going with cin
for now.

getline like fgets might just confuse him, at the present.

getline Reference

from getline reference..

Quote

Characters are extracted until either (n - 1) characters have been extracted or the delimiting character is found (which is delim if this parameter is specified, or '\n' otherwise).


and

Quote

The ending null character that signals the end of a c-string is automatically appended


Just an opinion of course.

Best Wishes

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#11 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: conflict between strftime and strlen

Posted 15 April 2012 - 04:51 PM

Quote

Yes counting does start at zero not at one so...
an array of '7' like

char ID[7];

would be 8 characters long wouldn't it ?

01234567
12345678

see what I mean ?


I didn't read everything perfectly but I don't think anyone corrected this mistake. an array like ID[7] would be *7* elements long

the indexes would 0123456
Was This Post Helpful? 0
  • +
  • -

#12 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 275
  • View blog
  • Posts: 1,778
  • Joined: 20-September 08

Re: conflict between strftime and strlen

Posted 15 April 2012 - 04:58 PM

Not cin.getline ... please don't use that in C++ unless you really have to :(

'getline( cin, lineStr )' was what I suggested :)

See this ref:
http://www.cplusplus.com/reference/string/getline/

Was This Post Helpful? 0
  • +
  • -

#13 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 762
  • View blog
  • Posts: 2,214
  • Joined: 20-March 10

Re: conflict between strftime and strlen

Posted 15 April 2012 - 05:25 PM

View Postishkabible, on 15 April 2012 - 11:51 PM, said:

Quote

Yes counting does start at zero not at one so...
an array of '7' like

char ID[7];

would be 8 characters long wouldn't it ?

01234567
12345678

see what I mean ?


I didn't read everything perfectly but I don't think anyone corrected this mistake. an array like ID[7] would be *7* elements long

the indexes would 0123456


Yeah Ishka good catch,

Obviously not paying attention at that point..

To clarify

An array of 7 would indeed be

0123456
1234567 elements

So char ID[7];

Would go from ID[0] to ID[6]

But not as IsoChronous thought
That to store 6 characters in the array he/she
would have to declare an array of 7 elements.

I was too busy thinking about fgets I think , sorry.

Best Wishes
Snoopy.
Was This Post Helpful? 0
  • +
  • -

#14 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 762
  • View blog
  • Posts: 2,214
  • Joined: 20-March 10

Re: conflict between strftime and strlen

Posted 15 April 2012 - 05:38 PM

View PostDavid W, on 15 April 2012 - 11:58 PM, said:

Not cin.getline ... please don't use that in C++ unless you really have to :(

'getline( cin, lineStr )' was what I suggested :)

See this ref:
http://www.cplusplus.com/reference/string/getline/


Sorry David,

I am doing all this on my iPhone
No access to a computer at the moment.

That'll teach me I suppose.

I did actually think you were recommending
the OP used cin.getline.

It did strike me as a bit odd at the time..

Never mind yeah I suppose he could change
ID from an array of char to

string ID[6]; or just string ID;

I have have no idea if the OP has covered
string yet ?

It is quite an old book IsoChronous is using
hence the unusual headers in a C++
program and everything else that's wrong
I suppose.

Anyway sorry I do apologise.

Best Wishes
Snoopy.

This post has been edited by snoopy11: 15 April 2012 - 05:45 PM

Was This Post Helpful? 0
  • +
  • -

#15 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 275
  • View blog
  • Posts: 1,778
  • Joined: 20-September 08

Re: conflict between strftime and strlen

Posted 15 April 2012 - 06:13 PM

Quote

... I did actually think you were recommending
the OP used cin.getline ...


Does 'getline( cin, lineStr )' look like 'cin.getline( ... )' ?

It's the op's we need to apologize to ... and to stop confusing :)

Anyway ... there has been much 'exposed' here for this op to consider when coding in C++

Main recommendations here when coding in C++ ...

Enjoy the ease of coding with C++ strings and avoid C strings unless you really have to use them.
Corollary: Use C++ library containers and functions rather than 'grow your own'.

General recommendations when coding:
Use clear logic flow in your program
Use functions for each task with descriptive names to aid the above
Start small with a working shell that does/gives output that it is supposed to ... and grow your code stepwise from there.

This post has been edited by David W: 15 April 2012 - 06:45 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1