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: Matt Hiller <hiller at redhat dot com>
- Date: Wed, 6 Jun 2001 14:33:32 -0700 (PDT)
- cc: gcc-help at gcc dot gnu dot org
On Wed, 6 Jun 2001, david smith wrote:
> #include <stdio.h>
>
> main(){
> char* username;
> printf("Username:");
> scanf("%s", &username);
> }
In addition to what everyone else has said about setting aside
space for username before using it and avoiding scanf in situations like
this to begin with:
Also bear in mind that scanf expects a (char *), not a (char
**). So correct code would look more like:
main ()
{
char username[20];
scanf ("%s", username);
}
That is, pass username itself to scanf. Don't pass &username; that
does the wrong thing.
Matt