This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: scanf, linux and solaris
- To: david smith <nextl at angelfire dot com>
- Subject: Re: scanf, linux and solaris
- From: Torleif Sandnes <tosa at telelogic dot no>
- Date: Wed, 6 Jun 2001 16:01:44 +0200 (MET DST)
- cc: gcc-help at gcc dot gnu dot org
> Hi, I've been trying to scan in a string using scanf. The following code works fine on Solaris but breaks on Linux(tested on two different boxes) with a seg fault. Currently it breaks when the username is longer than 10 chars, on a previous attempt before rebooting it would break when the username was longer than 6 chars.
> Any help would be appreciated.
>
> #include <stdio.h>
>
> main(){
> char* username;
> printf("Username:");
> scanf("%s", &username);
> }
I think you will have to allocate memory with malloc() before reading
anything into the memory pointed to by username.
regards
Torleif Sandnes