I have a normal text file as below:
Debdipta 1234567 8 rajat 123432 4 Kaushik 685784 7 djghkvnfj 213122 6
I want to delete a string from this file ex:below-
Debdipta 1234567 8 Kaushik 685784 7 djghkvnfj 213122 6
You can see that rajat and its corresponding field is deleted:
I want to do this trough C?
I can file this string and put file pointer there through following code:
fseek(fp, 0, SEEK_SET);
while(!feof(fp))
{
fgets(strFileMem, MAX_PATH, fp);
fseek(fp, 0, SEEK_CUR);
if( NULL == strstr(strName, strFileMem) )
{
break;
}
}
int ierr = fputs(" ", fp);
ierr = fputs(" ", fp);
Any idea what to put in fputs???
any other code?
thanks
Possible pseudo-code solution:
The biggest problem you have, is that you want to write to the same file you read from. This is not easy. It’s much easier to read from the original file, while writing to a temporary file. When done, rename (or copy) the temporary file to the original file.