Mail Archives: djgpp/1998/07/11/21:45:28
Okay... I feel really stupid asking this and should be well below me, but I've
never had much experience with file i/o in C/DJGPP.
I'm trying to write a program that does this (again, C, DJGPP):
1) takes the first command line parameter as a filename (obvious)
2) opens the file. coughs up an error if any. File is binary and can contain
nulls in-line. Also very large (~500 kb).
3) reads the file into a buffer. Search for a specific string. If found it
needs to be able to write to that offset.
4) write changes to the file without corrupting anything. It's overwritting
information, not inserting anything new.
FILE *fp;
char *my_buffer, *offset;
if (argc) {
fp = fopen (argv[1], "rb+"); // or whatever open for read/write binary is
if (ferror (fp)) {
printf ("There was an error...");
return;
}
// best way to read the data into my_buffer?
my_buffer = offset = (char *)malloc (sizeof(char) *
func_that_gets_file_size(fp));
readinto(fp); // should i use fread() or something else?
strchr (offset, "my_string");
if (offset) {
strcpy (offset, "newstring");
}
// write buffer to file
}
Thanks for your patience.
--
J Barlow
------------
Junk email will be forwarded to system
administrators.
------------
- Raw text -