
Originally Posted by
Matticus
Fair enough - you should still be checking that the file has successfully opened before accessing it, though.
Indeed - the suggestion I offered assumed this.
--------
In response to your next post - this is quite different than what you originally posted.
Try this:
- Create and post a simple, yet complete, code example that compiles (with your compare included)
- Post what is contained in a sample ".text" file
- Explain exactly what you are entering, and the result you are getting
well here this the full code
Code:
FILE *ptr_file;
char buf[50],m[50];
ptr_file =fopen("abc.text","r");
if (!ptr_file)
printf("Error opening file");
else
{
while (fgets(buf,50, ptr_file)!=NULL)
printf("%s",buf);
}
printf("\nEnter string:");
scanf("%s",&m);
ptr_file =fopen("abc.text","r");
fscanf(ptr_file,"%s",buf);
h=strcmp(buf, m);
if (h==0)
printf("\n matched");
else
printf("\n Not matched");
my file 'abc' contains the following
a@b.c
d@e.f
h@i.j
So i enter various string to find if they are matched or not.