This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: scanf, linux and solaris


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]