D
Dong Ge
Hi!
I am a beginner of C.
I want to delete some characters or a whole line in a text file. I
have tried the "fprintf", "fputs", "fwrite", but no one of them can
run rightly.
In the below codes, the "str1" is one text line , in fact. I want
replace "str1" (the whole line) with the "str3". In my case, "str3" is
shooter than "str1", But I will get some strange code that can not be
read.
Thanks in advance!
if ((cfPtr = fopen("client.dat","r+")) == NULL)
printf ("File counld not be opened. \n");
else
{
while (!feof(cfPtr))
{fgets(str1, 200, cfPtr);
printf ("OK!");
if (strstr(str1, str2))
printf ("NO!");
{fseek (cfPtr, ftell(cfPtr)-strlen(str1)-1,
SEEK_SET);
fwrite (str3, strlen(str1), 1, cfPtr);
exit();
}
}
fclose(cfPtr);
}
I am a beginner of C.
I want to delete some characters or a whole line in a text file. I
have tried the "fprintf", "fputs", "fwrite", but no one of them can
run rightly.
In the below codes, the "str1" is one text line , in fact. I want
replace "str1" (the whole line) with the "str3". In my case, "str3" is
shooter than "str1", But I will get some strange code that can not be
read.
Thanks in advance!
if ((cfPtr = fopen("client.dat","r+")) == NULL)
printf ("File counld not be opened. \n");
else
{
while (!feof(cfPtr))
{fgets(str1, 200, cfPtr);
printf ("OK!");
if (strstr(str1, str2))
printf ("NO!");
{fseek (cfPtr, ftell(cfPtr)-strlen(str1)-1,
SEEK_SET);
fwrite (str3, strlen(str1), 1, cfPtr);
exit();
}
}
fclose(cfPtr);
}