I wrote a small test program to read a file of data and print each
line, but it's only printing the 2nd line out of 3 total lines.
The test file, "foo.txt", has 3 lines:
7388: Zn->Z0 Run coward!
8473: Q1->P2 HAHAHAHAHA!
8381: G3->EVERYONE ok ok ok!
But when I run my progam it only prints the second line:
about to open file for reading
testing if fp stream was opened
entering while loop
about to call fgets
about to call printf
8473: Q1->P2 HAHAHAHAHA!
about to call fgets
about to call printf
closing file
about to exit
Also what does this warning mean and how can I eliminate it:
foo.c: In function 'main':
foo.c:33: warning: incompatible implicit declaration of built-in
function 'exit'
Here is my code:
#include <stdio.h>
int main(void)
{
FILE *fp;
char s[80];
printf("about to open file for reading\n");
fp = fopen("foo.txt" ,"r");
printf("testing if fp stream was opened\n");
if (fp != NULL)
{
printf("enterin g while loop\n");
while ( (fgets(s, sizeof(s), fp)) != NULL)
{
printf("about to call fgets\n");
fgets(s,sizeof( s),fp);
printf("about to call printf\n");
printf("%s\n",s );
}
}
printf("closing file\n");
fclose(fp);
printf("about to exit\n");
exit(0);
}
Lisp 9000
line, but it's only printing the 2nd line out of 3 total lines.
The test file, "foo.txt", has 3 lines:
7388: Zn->Z0 Run coward!
8473: Q1->P2 HAHAHAHAHA!
8381: G3->EVERYONE ok ok ok!
But when I run my progam it only prints the second line:
about to open file for reading
testing if fp stream was opened
entering while loop
about to call fgets
about to call printf
8473: Q1->P2 HAHAHAHAHA!
about to call fgets
about to call printf
closing file
about to exit
Also what does this warning mean and how can I eliminate it:
foo.c: In function 'main':
foo.c:33: warning: incompatible implicit declaration of built-in
function 'exit'
Here is my code:
#include <stdio.h>
int main(void)
{
FILE *fp;
char s[80];
printf("about to open file for reading\n");
fp = fopen("foo.txt" ,"r");
printf("testing if fp stream was opened\n");
if (fp != NULL)
{
printf("enterin g while loop\n");
while ( (fgets(s, sizeof(s), fp)) != NULL)
{
printf("about to call fgets\n");
fgets(s,sizeof( s),fp);
printf("about to call printf\n");
printf("%s\n",s );
}
}
printf("closing file\n");
fclose(fp);
printf("about to exit\n");
exit(0);
}
Lisp 9000
Comment