Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: comp.lang.c Subject: Re: Help Message-ID: <3646@utcsri.UUCP> Date: Mon, 17-Nov-86 12:40:48 EST Article-I.D.: utcsri.3646 Posted: Mon Nov 17 12:40:48 1986 Date-Received: Mon, 17-Nov-86 13:38:38 EST References: <408@ethz.UUCP> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 23 Summary: In article <408@ethz.UUCP> lubich@ethz.UUCP (Hannes Lubich) writes: >Well, I'm trapped. >When using something like : > while (fgets (teststring, 100, myfptr) != NULL) ... bombs on return... >Furthermore when I declare teststring as : char teststring[]; >the above result appears but when I try to declare it as >char *teststring; I get a 'Bus error' at once. > >Could somebody give me a hint about that misterious 'fgets' ? Did you try 'char teststring[100]'? fgets doesn't allocate storage for you. When you declare 'char teststring[];', you get a zero-byte array, and then pass its address to fgets, meanwhile you are telling fgets that there are 100 bytes there. So fgets scribbles all over your stack frame, and the return address is destroyed. If you say 'char *teststring', you are passing the pointer itself to fgets without initializing it to anything. So fgets writes the string to an undefined area. -- ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg Have vAX, will hack...