You will not be able to 'edit' directly, in the sense of a user's impression of using an editor. In general, you need to open() the file, read() the entire file into memory (or a temporary file), close() the file, and then open() the file anew. You will need to write() from the stored copy to the new version of the file, part-by-part, until you encounter the part where you will insert the desired characters. Write() the desired characters, and then resume writing the remainder of the stored original file. Then close() the file.
The italicized words above are the standard C functions you will need to use (hint: man is your friend). There is also a parallel set of functions that operates on streams: fopen(), fread(), fwrite(), fclose(), and the helpful, higher level, fscanf(), and fprintf(). See also: eof()/feof().
While learning this stuff, you will do yourself a favor by writing some simple test programs that open, read, write and close files in very simple ways. Your greatest challenge may be parsing the input file into lines, which might be easier to do with fscanf().
--- rod.
|