Name: C newbie /r/ your help 2012-12-08 11:26
test01.txt is a file containing this:
stallman richy 1154
the program should find stallman, then write the whole line.
The problem is strcmp is returning -9 in the search function.
thanks.
stallman richy 1154
the program should find stallman, then write the whole line.
The problem is strcmp is returning -9 in the search function.
#include<stdio.h>
#include<string.h>
FILE *f;
void search(){
int i,r;
i=r=0;
char prname[15],lrname[15],ed;
printf("lrname?\n");
gets(lrname);
puts(lrname);
while(ed!='\t'){
ed=fgetc(f);
prname[i]=ed;
i++;
}
prname[i]='\0';
puts(prname);
printf("ed is %c\n",ed);
//this line
printf("compare %d\n",strcmp(lrname,prname));
if(strcmp(lrname,prname)==0){
r=1;
while(ed!='\n'){
printf("%c",ed);
ed=fgetc(f);
}
}else{printf("nope\n");}
}
int main(){
f=fopen("test01.txt","r");
search();
fclose(f);
return 0;
}thanks.