From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: What's wrong???? Date: Mon, 29 Dec 1997 20:02:42 -0500 Organization: Cornell University (http://www.cornell.edu/) Lines: 48 Sender: asu1 AT cornell DOT edu (Verified) Message-ID: <34A84832.CD2C01C@cornell.edu> References: <34A6E7A9 DOT 35B1E68D AT usa DOT net> NNTP-Posting-Host: cu-dialup-0041.cit.cornell.edu 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 Rune Lanton wrote: > > I wrote this little program in DJGPP, or at least I tried, but > something went wrong!!!! for your own benefit, i would recommend using ANSI prototypes. > This code you see here works just fine when I try to read small files, > less than 1000 bytes I think, but when I try to read bigger files it > doesn't work. > WHY!!!!!!! > > Here's the code: > > #include > > void main(arg_counter, arg_pointers) > int arg_counter; > char *arg_pointers[]; like, using int main(int argc, char *argv[]) here would not hurt. there is no guarantee that the non-ANSI style will continue to work. in any case, i did not compile your program but your problem probably has to do with file_buffer. file_buffer is an unitialized pointer. below, you do: > *file_buffer = malloc((file_size)+512); which converts the pointer returned by malloc into int (because you did not include where malloc is declared. if you had done that and turned on -Wall, you would have known about this) and writes these four bytes into some unknown location depending on the value of file_buffer (which you have not initialized.) that probably causes a segmentation violation at random times. if you had initialized file_buffer to NULL to begin with, and were running under dos with cwsdpmi as your dpmi server, you would have caught this error easily. hth. -- ---------------------------------------------------------------------- A. Sinan Unur Department of Policy Analysis and Management, College of Human Ecology, Cornell University, Ithaca, NY 14853, USA mailto:sinan DOT unur AT cornell DOT edu http://www.people.cornell.edu/pages/asu1/