I want to write an input validation, users can input name with whitespace, if it is null
or exceed the maximum array length, it will jmp
to the beginning. However, when the input is too long, \n
would be left over the second turn, which means scanf_s
would receive the value automatically in the second turn. So I imagine is there a method like Java fflush
in the inline assembly language to clear keyboard input every turn? This is my code:
char inputName[] = "%20[^\n]";
char name[20];
int validNum;
_asm{
startInput:
lea eax, name
push eax
call scanf_s //this is the problem part
add esp, 8
computeLength:
lea ebx, name
...
inc validNum
cmp [ebx], '\0'
je validate
validate:
cmp validNum, 20
jg startInput
}