F
Francis Bell
Hello, I've got a 25 line file with lines of data like this:
sp/spinnerbait/AAA Lures/Mad Phil/silver/bass/1/1
The first field is the code that determines what to do. I need to loop
through this data file and, based on that first field, execute different
cases in a switch statement (yes, there's only one now...I'm in a
building process, and I need to get the first one to read first.).
However, it's only going through 1 time and it should be 3 (there are
three lines in the file with sp as the first field). What am I doing
wrong?! Thanks.
int code;
code = readInFirstChars(fin);
while (!fin.fail())
{
switch (code)
{
case 1:
{
readInASpinnerbait(fin, spinList);
}
default:
{
fin.ignore(80, '\n');
}
}
code = readInFirstChars(fin);
}
int readInFirstChars(ifstream &fin)
{
char first;
char second;
int code = 999;
char junk = '/';
first = fin.get();
if (first == 's')
{
second = fin.get();
}
if (second == 'p')
{
code = 1; // 1 is for Spinnerbait
return code;
}
else if (second == junk)
{
fin.ignore(80, '\n');
return code;
}
return code;
}
sp/spinnerbait/AAA Lures/Mad Phil/silver/bass/1/1
The first field is the code that determines what to do. I need to loop
through this data file and, based on that first field, execute different
cases in a switch statement (yes, there's only one now...I'm in a
building process, and I need to get the first one to read first.).
However, it's only going through 1 time and it should be 3 (there are
three lines in the file with sp as the first field). What am I doing
wrong?! Thanks.
int code;
code = readInFirstChars(fin);
while (!fin.fail())
{
switch (code)
{
case 1:
{
readInASpinnerbait(fin, spinList);
}
default:
{
fin.ignore(80, '\n');
}
}
code = readInFirstChars(fin);
}
int readInFirstChars(ifstream &fin)
{
char first;
char second;
int code = 999;
char junk = '/';
first = fin.get();
if (first == 's')
{
second = fin.get();
}
if (second == 'p')
{
code = 1; // 1 is for Spinnerbait
return code;
}
else if (second == junk)
{
fin.ignore(80, '\n');
return code;
}
return code;
}