I am making a program that will check a documents nd print the number of times that it had the word 'pets'.
The program runs ok, but it prints: I got the word: <null>.
The code is included please let me know what I am doing wrong.
Thank you
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
int main (){
char c;
char inputText[500];
int countSame=0;
FILE* inputFile;
inputFile=fopen("C:\\Documents and Settings\\User\\My Documents\\GPA.txt","r");
if (inputFile==NULL){
printf("Failed to open");
exit(-1);
}
while ((c=scanf(inputFile))!=EOF){
fscanf(inputFile,"%s",inputText);
printf("I got the word: %s\n",c);
}
if( strcmp(inputText, "pets" ) == 0 ) {
countSame++;
}
printf("There are %i matches for pets\n", countSame);
system("Pause");
}