Write to specific line of file

To read it is simple:
1
2
3
4
5
6
7
8
9
  char ab[128]="LOOL";
  int languagei4;
     FILE *file5 = fopen ( "home/alex/Desktop/example.txt", "r" );
     for ( languagei4 = 0; languagei4 < 3; ++languagei4 ) //read 3rd line
     {
  fwrite (ab , 1 , sizeof(ab) , file5 );
     }
     fclose ( file5 );
  return 0;


But to write seems to be more difficult!
This doesn't work:
1
2
3
4
5
6
7
8
9
  char ab[128]="LOOL";
  int languagei4;
     FILE *file5 = fopen ( "home/alex/Desktop/example.txt", "r" );
     for ( languagei4 = 0; languagei4 < 3; ++languagei4 )
     {
  fwrite (ab , 1 , sizeof(ab) , file5 );
     }
     fclose ( file5 );
  return 0;
Make a copycat cat program (the input goes to output). When you reach the desired line: pause, paste your string, continue.
Last edited on
Topic archived. No new replies allowed.