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:
Code:
while (getline(inFile, oneCourse))
{
++lineNum;
stringstream cStr(oneCourse);
vector<string> pCourse;
pCourse.push_back("add");
string piece;
while (cStr >> piece)
pCourse.push_back(piece);
//solution 1
if (!add_course(sched, pCourse))
cout << "(Import file: line " << lineNum << ")" << endl;
}
add_course: (args[1] contains a string of characters representing the days the class meets.)
Code:
if (!(args[1] == "o" || args[1] == "O"))
{
string week = "MTWRFS";
unsigned int weekPos = 0, dayPos = 0;
while ((dayPos < args[1].size()) && (weekPos < week.size()) )
{
if (toupper(args[1][dayPos]) == week[weekPos])
++dayPos;
++weekPos;
}
if (dayPos < args[1].size())
{
cout << "Error: add: days not valid. days can only include MTWRFS in chronological order" << endl;
return false;
}
}
DaysOfWeek nDays(args[1]);
I have found two 'solutions' to this problem.
If I replace //solution 1 with
Code:
pCourse[1]; //pCourse[1] contains the string that will be passed to the DaysOfWeek constructor
Also, 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.
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.