Presumably the file wasn't opened properly? Does /tmp/test.txt exist? Maybe change it to test.txt in the current directory. A program should always test to see if a file opened properly:
Code:
#include <stdio.h>
#include <stdlib.h> // exit()
int main() { // main returns int
FILE fp = fopen("test.txt", "r");
if (fp == NULL) {
perror("fopen");
exit(EXIT_FAILURE);
}
char buff[255];
fscanf(fp, "%s", buff);
printf("1: %s\n", buff);
fgets(buff, 255, (FILE*)fp);
printf("2: %s\n", buff );
fgets(buff, 255, (FILE*)fp);
printf("3: %s\n", buff );
fclose(fp);
return 0; // returning 0 means success
}
EDIT:
Now that I think about it, I guess the file is opening. Are you sure it contains text? Try a different file, perhaps the source file itself.