From: Jim Barlow Newsgroups: comp.os.msdos.djgpp Subject: Newbie question -- debug this plz Date: Sat, 11 Jul 1998 18:24:59 -0700 Organization: BCTEL Advanced Communications Lines: 41 Message-ID: <35A8106A.6B1FD58D@bc.sympatico.ca> Reply-To: Jim_Barlow AT bc DOT sympatico DOT ca NNTP-Posting-Host: vcta01m06-157.bctel.ca Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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. ------------