#include "stdafx.h"
#include "conio.h"
These aren't standard headers, and they aren't particularly useful for what you're trying to accomplish. You need to include the stdio.h header file in order to use printf and scanf.
int _tmain(int argc, _TCHAR* argv[])
I don't know why you define main like this. For most programs, you really only need to use one of the following:
Code:
int main(void) { /* ... */ }
int main(int argc, char *argv[]) { /* ... */ }
Which one you use will depend on whether you plan on using the arguments passed by the host environment.
So my question is, what's the proper way of scanning and printing short integers? (I guess it doesn't matter if it's signed or unsigned)
Code:
short int a;
if (scanf("%hd", &a) == 1)
printf("%d\n", a);
For short unsigned int, I suggest using the "%hu" format specifier. Note that the 'h' specifier isn't necessary for printf due to default argument promotions.
Also, in what interval can a short int store numbers?
It varies based on your C implementation. signed short has a minimum guaranteed range of -32767 to +32767 (inclusive), and unsigned short has a minimum guaranteed range of 0 to 65535. You can check their actual ranges by including the header file limits.h and checking the macros USHRT_MAX, SHRT_MAX, and SHRT_MIN. I strongly suggest assuming that each data type has their minimum guaranteed range (as specified by the standard) for the sake of writing portable code.