So, there is a text, for example: "I study at school", which is recorded in a file in the program. It is necessary to write the additional word "good" before the word school (in the same program). If I try to do this with the help of fprinf , then the word school is simply overwritten. How to do this without overwriting words, and shifting them to the right?
#include <stdio.h> #include <stdlib.h> int main (void) { FILE *fp; if ((fp = fopen ("skul.txt", "w")) == NULL) { printf ("ERROR of open file skul.txt\n"); exit (EXIT_FAILURE); } fprintf (fp, "i lern in skul"); if (fclose (fp) != 0) { printf ("ERROR of exit from file skul.txt\n"); exit (EXIT_FAILURE); } if ((fp = fopen ("skul.txt", "r+")) == NULL) { printf ("ERROR of open file skul.txt\n"); exit (EXIT_FAILURE); } fseek (fp, 10L, SEEK_SET); fprintf (fp, "good "); if (fclose (fp) != 0) { printf ("ERROR of exit from file skul.txt\n"); exit (EXIT_FAILURE); } return EXIT_SUCCESS; }