I'm writing a program for homework that works fine on my XP box. I compiled the same program at school (UNIX), but it doesn't work there. I use Dev-C++ on the XP computer and g++ at school, so the compilers should be about the same.
The weird thing is that I can fix the error on the UNIX version just by accessing the variable in question (not doing anything with it, just using the variable name as a statement.)
The program is a scheduling program.
The program is too long to post, so I'll post the snippets that are involved so far. The problem seems to be in the import_course function, which should import a schedule from a file. It uses the add_course function, which can be called by the user as well to input a single course from the console. The first part of a course listing is the days that the class meets. This is where the problem lies. If is use the add function from the console, everything works fine. If I use the import function, it adds an F to every day listing:
import_course:add_course: (args contains a string of characters representing the days the class meets.)Code:
while (getline(inFile, oneCourse))
while (cStr >> piece)
if (!add_course(sched, pCourse))
cout << "(Import file: line " << lineNum << ")" << endl;
I have found two 'solutions' to this problem.Code:
if (!(args == "o" || args == "O"))
string week = "MTWRFS";
unsigned int weekPos = 0, dayPos = 0;
while ((dayPos < args.size()) && (weekPos < week.size()) )
if (toupper(args[dayPos]) == week[weekPos])
if (dayPos < args.size())
cout << "Error: add: days not valid. days can only include MTWRFS in chronological order" << endl;
If I replace //solution 1 withAlso, if I comment out all of the above add_course function except for the constructor, everything works fine. I can't figure out what would be causing this error that it could be solved in both of these ways. The code in the add_course function doesn't change anything, and besides, it works when the add_course function is used without the import function calling it. However, without that section of code, everything works fine.Code:
pCourse; //pCourse contains the string that will be passed to the DaysOfWeek constructor
Since the extra 'F' only occurs when I call the import function (and then, only in UNIX), it would seem the error is there. The 'solution' is just to use the variable in a useless statement? It's easily fixable doing that, but I'm nervous that whatever's causing this could be causing problems elsewhere I don't know about yet.
As always, any help is most appreciated.