Date: Thu, 7 May 1998 14:58:10 +0200 (MET DST) From: Olivier Perron To: Ville Lundberg Cc: djgpp AT delorie DOT com Subject: Re: Segmentation fault in UNIX In-Reply-To: <35519D05.18BA@cc.hut.fi> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Thu, 7 May 1998, Ville Lundberg wrote: > Why does this simple piece of code cause a "Segmentation fault" in UNIX, > while it works just fine in DOS? The error occurs when the code hits the > getpass() function. > > #include > #include > #include > > void main(void) { > char *lin, *pin; > > do { > printf("Enter name and password:\n"); > printf("Name:"); > gets(lin); > } while(strcmp(lin, "")==NULL); > > pin = getpass("Password:"); > > // And here's nothing more than opening a file and couple printf:s > > } You should reserve some space for lin and pin ! (like: char lin[80], pin[80]; ) It's a miracle that your code worked on DOS.