While I admit it's not homework, I would appreciate a little programming help with a chunk of code I'm working on, if you guys don't mind. It's C, specifically C99.
*sneezes from dust*
Code:
for(pos = 0; pos <= length; pos++)
{
// [truncated]
// watch for comments
#ifdef WINNT
else if(config[pos] == ';')
#endif
#ifdef UNIX
else if(config[pos] == '#')
#endif
{
commenting = TRUE;
}
// skip over blank lines
#ifdef WINNT
else if(config[pos] == '\r' &&
config[pos + 1] == '\n')
#endif
#ifdef UNIX
else if(config[pos] == '\n')
#endif
{
// ???
continue;
}
// parse standard command names
else if((config[pos] == 'S' || config[pos] == 's') &&
(config[pos + 1] == 'T' || config[pos + 1] == 't') &&
(config[pos + 2] == 'D' || config[pos + 2] == 'd') &&
isctrlspacer(config[pos + 3]) == TRUE &&
parsingcommand == TRUE)
{
// fill in later
}
// [truncated]
else
{
configfile_error = TRUE;
}
continue;
}
As you can see here, I have a for loop that runs through a configuration file, doing what it will with the data contained. Albeit it's truncated for privacy reasons, towards the top are handlers for errors, and afterward comments - what I'm having an issue with is the else if block handling newlines in the middle there. The logic of the for loop is to have a single central location to break out of upon an error by setting a variable and continuing into the next iteration (soft breaks), but I'm not sure exactly how I'm supposed to handle the code for newlines. Obviously I want to skip into the next iteration and continue scanning the file, but I'm unsure whether an explicit continue is needed when there's a continue that it executes anyway after it iterates the conditional. How exactly is that supposed to be written? :v