Hello,
I'm learning C with help of a book and one of the challenges is to create a number guessing program.
The compiler doesn't give me an error but when i run the program and enter a number
it exits with "Segmentation fault (core dumped)" error:
Code:
#include <stdio.h>
#include <ctype.h>
main()
{
int iRandom = 0;
char cResponse = '\0';
srand(time());
iRandom = (rand() % 10) +1;
printf("\nGuess a number between 1 and 10: ");
scanf("%c", cResponse);
if isdigit(cResponse)
{
if (cResponse == iRandom)
printf("\nCongratulations, you guessed correct!");
else
printf("\nSorry, you guessed wrong.");
printf("The correct number was: %d", iRandom);
}
else
printf("You did not enter a number");
}
Can anyone help please?