Hey guys,
Im learning C online, and its hard somtimes to understand the concepts, w/o being in class asking questions. I was wondering hat would be the easiest and fstest way to understand numeric validating(no characters) and could anyone break it in easy steps? im new, but really excited about C and will learn fast. I found this program in one of the books, but it doesnt really explain whats going on under the hood, if there is an easier way of doing it please let me know.
I dont understand things, that happens in the loop.,
Cheers, and thanx a lot for your time!!! )
#include<stdio.h>
int get_int(void);
main()
{
printf ("Enter an integer:");
get_int();
printf ("Good!\n");
}
int get_int(void)
{
int input;
char ch;
while (scanf("%d", &input) != 1)
{
while ((ch = getchar()) != '\n')
putchar(ch); // dispose of bad input
printf(" is not an integer.\nPlease enter an ");
printf("integer value, such as 25, -178, or 3: ");
}
return input;
}