The problem is that you are trying to print the FILE pointer instead of the contents of the file - you need a variable to store this.
It's been interesting to see other approaches. Here is an implementation with fscanf() -
#include <stdio.h>
#define FILENAME "test.txt"
int main(void)
{
FILE *myfile;
char string[81] = {'\0'};
myfile=fopen(FILENAME , "r");
if(myfile == NULL)
{
printf("The file test.txt could not be found! Exiting...\n");
return -1;
}
while(fscanf(myfile, " %80[^\n]s", string) != EOF)
{
printf("%s\n", string);
}
fclose(myfile);
return 0;
}
When you open a file, if the operation fails NULL will be returned, it's good practice to check this explicitly so that you know what's gone wrong.
fscanf() returns the number of successful reads (it would be 1 here, for 1 conversion to a string), or EOF if the end of file has been reached. The format string uses a space first of all to remove any and all preceding whitespace (newlines, spaces, tabs) in the input stream.
Using a field width specifier (the 80) in scanf() functions means that only this many characters will be read, so that the input can't go past the allocated space - useful!
The [^] means that the stream will be read only up to encountering the specified characters. [^\n] is a way of getting strings with whitespace in them, as the scanf() family usually only reads up to encountering whitespace for strings. Note that the newline will not be removed (it's still first in the stream).
It then prints the string, with a newline added. This program will loop through as many lines (of up to 80 chars, separated by newlines) are in the file. If you wanted to keep the lines you could make string an array of char arrays and increment each time. This is where the first space in the fscanf() format string comes in handy, it will remove the newline character (and any other preceding whitespace) that is still at the beginning of the stream.
I haven't found any definitive tutorials for learning C online, but there are plenty available. The current standard isn't beginner friendly but a draft form is freely available: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf
Another good resource (but not a tutorial) is http://c-faq.com/
The best reference for ins and outs of standard library functions that I've found is Harbison & Steele's C: A Reference Manual - but unfortunately it's not free.