I created a very simple program with menus that take a value, and then store it in the local value of the variable and, finally, with the second option, the program prints the value.
my question is: Why does the program work only if I add "h" to the scanf parameter? In other words: what is the relationship between scanf () and my local variable of int value?
thanks!
pS (I used Dev-C ++ (GCC) to compile it. It works with Visual Studio)
#include <stdio.h> main () { int value = 0; short choice = 0; do { printf("\nYour Choice ---> "); scanf("%d", &choice); /* replace with "%hd" and it works */ switch (choice) { case 1: printf("\nEnter a volue to store "); scanf("%d", &value); getchar(); printf("\nValue: %d", value); break; case 2: printf("\nValue: %d", value); break; } } while (choice < 3); getchar(); }
Mario source share