Sorting Strings alphabetically

Pages: 12
Are you linking all the files in the same executable?
I'm tempted to ask you to post your pseudocode :P

Normally, when writting code, I do a bit then compile, do a bit more and compile. so on....

try this, just comment out the body of each method using /* */ tags, and see if your base classes/methods with simply method declarations and variable declarations in header will work, compile..

if they do then start to un-comment and compile some more.
Last edited on
Bazzy: in my payRoll.cpp I am linking in each of the header files as you can see. Then in each of the .cpp's I have, I include my corresponding header files. And in my EmployeeList.h I include my Employee.h file.

When I compile it, I type g++ EmployeeList.cpp Employee.cpp payRoll.cpp

So if what your getting at is an infinite loop when I try to compile it, I don't think that is happening.

gcampton: When I was writing it, I compiled each individually:
g++ -c Employee.cpp
g++ -c EmployeeList.cpp

Those both compile fine, but then when I try to stick them all together, I get the core dump.

So those should be ok I think.

I will try commenting out each function in my main program though, see if that helps me find the source.
It looks like what is happening is the following:

Any time I try to call something from my EmployeeList.h/EmployeeList.cpp program, there is the error message. I commented out everything except my main, and my menu runs fine. Then I tried adding each function while leaving each other commented, and then the error pops up (with quite a few less of the functions appearing in the error statement).

So perhaps I am screwing up on my function calls from the EmployeeList.cpp/EmployeeList.h file?
Ok I solved that error by instead of declaring and passing to my functions, instead I declared inside each function. I still don't understand why I couldn't declare and pass though... if anyone has an answer for that that would be appreciated.

And so I was able to compile and run, but then didn't get far. I made a very stupid mistake back in the first part of my program, go figure. I made my names characters instead of character arrays, so anytime I would try to type a name, I would get a sec fault, core dump. Now here is my new problem...

csci2>g++ payRoll.cpp EmployeeList.cpp Employee.cpp
Employee.cpp: In member function `void Employee::EmployeeInfo(char*, char*, int, double, int)':
Employee.cpp:16: error: incompatible types in assignment of `char*' to `char[30]'
Employee.cpp:18: error: incompatible types in assignment of `char*' to `char[30]'

14
15
16
17
18
19
20
21
22
23
24
        void Employee::EmployeeInfo(char *name1, char *name2, int ident, double payRate, int hoursWorked)
        {
                fName = new char[strlen(name1) +1];
                strcpy (fName, name1);
                lName = new char[strlen(name2) +1];
                strcpy (lName, name2);
                id = ident;
                rate = payRate;
                hours = hoursWorked;
        }


My fName and lName are declared as char arrays. Is there anyway I can make the new operator return a nonpointer value?

Or if not, how do I need to modify my declaration to fit?

1
2
3
4
5
6
7
        private:
                int id;
                char fName[SIZE];
                char lName[SIZE];
                double wage;
                double rate;
                int hours;
Last edited on
Topic archived. No new replies allowed.
Pages: 12