char data[30];
int e;
gets(data);
cin >> e;
gets (data);
problem: the second gets() is not working - not asking for data from
keyboard at least.
After reading the numeric input ('cin >> e') the stuff following is still
sticking in the input stream. In particular, the "\n" sought by 'gets()'
is still there. Thus, 'gets()' finds an empty line (the stuff following
the integer in the input) and happily finishes.
To avoid this problem, you should probably skip trailing garbage following
the numeric input. What exactly constitutes this garbage is somewhat
dependent on the use. The easiest would be to skip all whitespace following
the numeric input:
std::cin >> e >> std::ws;
This would, however, also skip empty lines, lines made up only of white
space, and leading whitespace. Often it is more desirable to only skip
the stuff up to and including the next newline:
std::cin >> e;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
BTW: 'gets()' is to be avoided in all cases! It is just present due to
legacy code (and it is legacy in all meanings of the word) which still
uses it. This function is extremely prone to buffer overruns and one of
the biggest offenders when it comes to whatever kind of attack. The
problem with this function is that you cannot pass the maximum size of
the buffer in. You should replace it by 'fgets()' if you want to really
use a C function or, IMO preferably, with 'std::getline()'.