Below is the code I am using so far. Below code no problem but it was too long and less efficient.
So, I wonder if anyone got a more good suggestion to restricting input to number only. Thanks you.Code:#include <stdio.h> int main(void) { char dummy[50]; int c_size[1], nFields; printf("Input class size (num of students): ", stdout); nFields = scanf("%d%1[^\n]", &c_size[0], dummy); while(1 != nFields || c_size[0] < 1) { printf("Invalid class size. Please try again.\n"); fputs("\nInput class size (num of students): ", stdout); fflush(stdout); while(0 != scanf("%*[^\n]")); nFields = scanf("%d%1[^\n]", &c_size[0], dummy); } }



LinkBack URL
About LinkBacks


