C programming - Help with opening text file and reading from it
Hello! in my code i want to open a text file and then read/print out the content off the file.
this is my code:
Code:
int main()
{
char s[20];
FILE * fp;
if((fp=fopen("bilar.txt", "r"))==NULL){
printf("Error! opening file");
exit(1);
}
fscanf(fp,"%s",s);
printf("%s",s);
fclose(fp);
return 0;
}
it prints out 1
and here is the text file (bilar.txt)that i want the code to open and print out:
volvo 2003 lastbil
volgswagen 2009 personbil
peugot 1969 personbil
scania 2001 lastbil
chevrolet 1971 personbil
ferrari 1959 personbil