Can someone tell me what is going wrong here?
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define ERROR 0
#define MAX_INPUT_LINE 80
#define print(x) {fputs(x,stdout);}
#define SUCCESS 1
int main (long argc, char *argv[])
{
int mode;
printf("1 for hexidecimal or 2 for binary");
scanf("%d", mode);
printf("\n\n\nThe value of mode is %d\n", mode);
return 0;
}
When I enter 2 for binary, I get this:
The value of mode is 2665564
Obviously I should get 2, what am I doing wrong?? Is it my compiler, is it bevcause I am using Cygwin? Why is mode not 2??
your scanf is wrong. should be:
scanf("%d", &mode);
The & tells the compiler to send scanf a pointer to mode (i.e. its address) and not the actual value of mode. That way scanf can put update mode with the new scanned value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With