Ask your own question, for FREE!
Computer Science 18 Online
OpenStudy (anonymous):

hello. In C programming, how can I check that the input received is an integer, and return an error message if it is not?

OpenStudy (anonymous):

Actually, it isn't easy because C basically doesn't support exception handling like newer language such as C++ However, here is a trick : basically, scanf will return 1 value if it is suceeded (the input is correct) int num; char term; if(scanf("%d%c", &num, &term) != 2 || term != '\n') printf("failure\n"); else printf("valid integer followed by enter key\n");

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!