www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/07/09:04:31

Date: Thu, 7 May 1998 14:58:10 +0200 (MET DST)
From: Olivier Perron <perron AT art DOT alcatel DOT fr>
To: Ville Lundberg <vlundber AT cc DOT hut DOT fi>
Cc: djgpp AT delorie DOT com
Subject: Re: Segmentation fault in UNIX
In-Reply-To: <35519D05.18BA@cc.hut.fi>
Message-Id: <Pine.GSO.3.96.980507144812.2621B-100000@rtbsci143s>
Mime-Version: 1.0

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 <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> 
> 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.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019