Don't use scanf
and never again use gets
.
Your problem can be solved by just using fgets
printf("
Team 2: ");
fflush(stdout);
char input[256]; // same size of eqTeam
fgets(input, sizeof(input), stdin);
if (input[0] != '
') {
strcpy(p->vetor.eqTeam2);
}
This will always read in a full line, but if the first character of the line is a newline, the user just pressed enter. If the first char is something else, the input is copied to the correct location. Note that the input buffer must be of a suitable size, here I just guessed one that is for sure not correct (but I lack the necessary info)
And one more thing, never flush stdin
, you have to fflush(stdout)
as fflush
is an output operation.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…