11

I am trying to take two variables as input using this code snippet:-

unsigned int i;

unsigned long int j;

scanf("%u",i);

scanf("%lu",j);

But this give rise to the following warnings :-

warning: format ‘%u’ expects argument of type ‘unsigned int *’, but argument 2 has type ‘unsigned int’ [-Wformat] warning: format ‘%lu’ expects argument of type ‘long unsigned int *’, but argument 2 has type ‘long unsigned int’ [-Wformat] Can anyone explain to me whats happening here?

Glenn
  • 822
  • 6
  • 9

1 Answers1

23

You need to add a leading &, as scanf takes pointers to the output parameters. Otherwise, it can not write to them.

scanf("%lu", &i);
slavemaster
  • 204
  • 1
  • 4
md5
  • 23,373
  • 3
  • 44
  • 93