I'm working on my first simple C program in Visual Studios 2017. The goal is to get two user inputs which have to be integers.
I go through the array and check if every character is an integer but it still returns "The input is not a valid number". Also after retrying 3 times the console crashes.
"projectExample.exe has triggered a breakpoint. occurred" is the displayed message.
int main()
{
char userInputM[10];
char userInputN[10];
//get the value of M from the user
printf("Enter a value for M: ");
fgets(userInputM, sizeof(userInputM), stdin);
//printf(userInputM);
//check that the entered value for M is a valid positive number
const int lenOfInput1 = strlen(userInputM);
for (int i = 0; lenOfInput1; i++) {
if (!isdigit(userInputM[i])) {
printf("The input is not a valid number. Try again");
printf("Enter a value for M: ");
fgets(userInputM, sizeof(userInputM), stdin);
printf(userInputM);
}
}
//check that the entered value for N is a number
//convert the user input for M to an int for calculation
//int factorM = atoi(userInputM);
//printf("%d", factorM);
//int result = calculate();
//int a;
//scanf("%d", &a);
}