Mail Archives: djgpp/1998/05/07/09:39:57
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.
Your `line' variable points to nowhere, so your program dereferences am
unitilialized pointer and crashes.
As to why doesn't it crash in DOS, it depends on your environment. I
think if you use CWSDPMI it will crash as well, but Windows doesn't
usually care if you dereference null pointers.
> char *lin, *pin;
Either use "char lin[80]", or allocate memory dynamically with malloc,
before you call gets(lin).
- Raw text -