gcc - Take a 4-digit input and automatically the computer press Enter -
i want user inputs 4-digit number computer press enter (meaning 4 digit input taken , taken program continue itself. user has no need press enter key). program written in c. using gcc compiler.
the getchar() function gets character without need press enter.
you can use for loop call getchar() function many times need it. loop runs, each character inserted in number array.
char number[4]; (i=0; i<4; i++) { number[i] = getchar(); getchar(); }
we can use sscanf() function convert char array int!
int num; sscanf(number, "%d", &num);
Comments
Post a Comment