replace a partucula string in C files

hi i am trying to search and replace a particular string in my program..

#include <stdio.h>
#include <string.h>
main()
{
FILE *fp;
char name[40];
char str[]="xyz";
clrscr();

fp=fopen("fle1.txt","w+");
while(fscanf(fp,"%s",name)!=EOF)
{
printf("%s",name);
if(strcmp(name,str)==0)
{
//fseek(fp,SEEK_CUR,5);
fprintf(fp,"%s","abc");
}
else
printf("\n\nno\n");
}
fclose(fp);
getch();
return 0;
}

here m trying to replace "xyz" with "abc" and its not happening..
can any1 please help me to do this..?
Please use the code formatting tags when posting code.

strcmp compares two strings for an exact match.
strstr searches one string for another and returns the location where it found it or null.

You may want to use strstr to do the search rather than strcmp.
Topic archived. No new replies allowed.