I'm trying to write a function that checks input. I've seen some code like this but they didn't get the input until it got int. My function should get the input and check it. It should be used like "check(input)"; Here is something I tried and failed;
char n[10];
fgets(n, sizeof(n), stdin);
strtol(n, NULL, 10);
int i;
for (i = 0; i < strlen(n); i++) {
while(! isdigit(n[i])) {
if (n[i] != '.') {
printf("Wrong! Enter again:");
fgets(n, sizeof(n), stdin);
}
}
}
return buf;