iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
>Alright... first off I hate fgets with a passion
How can you hate something you don't completely understand? Don't confuse ignorance of fgets (or C in this case) with any legitimate problems that it has.
Just because you don't know how to use something doesn't mean there's anything wrong with it.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
> if (*fp == NULL)
You could start here - never mind the rest of it.
Say
if (fp == NULL)
Man, didn't your compiler complain about that line?
> while( fgets(questions[x], sizeof(questions), fp) != NULL)
If you lie about the buffer size, then it's no better than gets()
Besides, if you want to read up to 25 lines, its
for ( x = 0 ;
x < 25 && fgets(questions[x], sizeof(questions[x]), fp) != NULL )
x++ ) {
char *p = strchr( questions[x], '\n' );
if ( p ) *p = '\0'; /* blow away a newline - if you want to that is */
}
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953