to get a single word from a file and compare would be something like this
Code:
#include <stdio.h>
#include <stdlib.h> /*for exit*/
#include <string.h>
char *getword(FILE *ffile);
int main(void){
FILE *myfile;
char example[4][]={"Saints","VooDoo","Hornets",LSU"};
char array[BUFSIZ];
int x=0;
myfile=fopen("temp","rb");
if(!myfile){
fprintf(stderr,"Error");
exit(0);
}
array=getword(myfile); /*gets one word(you would have to put this in a loop*/
while(x<4){
if(!strcmp("EOF",array)){
printf("End of File\n");
exit(0);
}
else if(!strcmp(example[x],array)){
printf("There is the word!!!!!!\n");
x++;
}
else{
x++;
}
}
char *getword(FILE *ffile){
char buffer[BUFSIZ];
char word[BUFSIZ];
char endoffile[]={"EOF"};
int y=0,int z=0;
if((fgets(buffer,sizeof buffer,ffile))!=NULL){
while(buffer[y]!=' ' || (ispunct(buffer[y])!=0) || buffer[y]!='\t' || buffer[y]!='\n'){
buffer[y]=word[y];
y++;
}
return word;
}
else
return endoffile;
}
I think that will work for a word. But once again I can't check