scanf, linux and solaris
Matt Hiller
hiller@redhat.com
Wed Jun 6 14:33:00 GMT 2001
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
More information about the Gcc-help
mailing list