Hi guys! I'm pretty new to C and I'm a bit confused about the File I/O stuff.
I'm trying to scan a word from a file. I can tell something is wrong with my code but I'm not sure whether it is the fscanf format or what.
Code:
char word; //word that will be read from the file
FILE *ifp = fopen( "myFile.txt", "r" ); //open myFile to read
if (ifp == NULL ) //if file doesn't exist
{
printf( "File does not exist\n" );
return -1; //return code
}
while (ifp == fopen( "myFile.txt", "r") != EOF)
{
fscanf(" %c", word);
}
Also, if I want to scan a word from a file, would I use %c or %s ?