I have got struck in a problem where I have the task to update the old line with a new line in a .txt file using C

39 Views Asked by At

I have opened the file in "r+" mode and tried to use fputs to replace old_line (line) with new_line (updated_line)

char updated_line[] = "Hello This was ABCD";
fseek(fp, -(strlen(line))-1, SEEK_CUR); 
fputs(updated_line, fp);

Given txt file data :

Hello This is ABCD
Studying in XYZ College

Output:

Hello This was ABCD
udying in XYZ College

The two characters "St" are missing from next line. How do I rectify this ?

0

There are 0 best solutions below