From: sparhawk AT eunet DOT at (Gerhard Gruber) Newsgroups: comp.os.msdos.djgpp Subject: Re: Segmentation fault in UNIX Date: Fri, 08 May 1998 13:02:30 GMT Organization: Customer of EUnet Austria Lines: 45 Message-ID: <3553edeb.3391725@news.Austria.EU.net> References: <35519D05 DOT 18BA AT cc DOT hut DOT fi> NNTP-Posting-Host: e014.dynamic.vienna.at.eu.net 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 Destination: Ville Lundberg From: Gruber Gerhard Group: comp.os.msdos.djgpp Date: Thu, 07 May 1998 14:37:41 +0300: >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 > >} No memory allocated for lin and pin. before you call gets() you have to have some line like if((lin = malloc()) == NULL) { fprintf(stderr, "not enough memory\n"); exit(1); } -- Bye, Gerhard email: sparhawk AT eunet DOT at g DOT gruber AT sis DOT co DOT at Spelling corrections are appreciated.