Mail Archives: djgpp/1998/05/07/09:04:31
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 -