Q:

gets (variable)

can anyone tell me why gets(abc) works with char[] but not with int?
 int abc;
 char name[] = "lolrofl";
 printf("Hello %s.\n",name);
 printf("\n >> ");
 fflush(stdin);
 gets (abc);
 printf("\n die zahl ist %i.\n",abc);
 system("Pause");
 return(0);

A:

The prototype for gets() is:

char* gets(char *s);

Note that the function DOES NOT read just a single character and place it in s; it actually reads an entire string into s. However, since gets() does not provide a way of specifying the maximum number of characters to read, this can actually read more characters into s than there are bytes allocated for s. Thus, this function is a serious buffer overflow vulnerability, and you should not  use this function, ever. There are alternative, safer functions which allow you to read input from the user such as fgets() and getc().
If you are using C++, then using the C++ I/O Stream Library (std::cin, std::cout, std::ostream, std::istream, std::fstream, etc.) is a far better way to perform input/output than using these other functions.
The function gets() is so dangerous, in fact, that in my development and coding custom search engine, I have taken out a promotion on gets and several other such functions warning not to use it!

A:

Because it only reads characters. Use scanf() for formatted reading.
By the way, since you appear to be using C++ (or at least your choice of tags says so), perhaps you should try std::cin/std::cout.

