The task of this code is to first generate 6 random integers, and then ask users for input, if user entered 6 integers then program move on, else it removes non-numeric value such as spaces, tabs or letters and ask user to make up the missing numbers.
The problem with my code is it always generate some random value.For testing purpose i just print out what i have in array answer after the second input
CASE 1:
First input:1234First output: YOu need to enter 2 more digits to complete your guessSecond input:56Second output:1 2 5 6 -38 -48 (it is supposed to be 123456)
CASE 2:
First input:12First output: YOu need to enter 4 more digits to complete your guessSecond input:3456Second output:1 2 0 0 3 4 (It is supposed to be 123456)
PLEASE HELP
#include <stdio.h>#include <stdlib.h>#include <ctype.h>int main() { int question[6]; int answer[6]; int history[6]; for (int i = 0; i < 6; i++) { int randomnumber = rand() % 6 + 1; question[i] = randomnumber; } char copy[100]; int count = 0; fgets(copy, sizeof(copy), stdin); // Take inputs first time for (int j = 0; j < 6; j++) { if (isspace(copy[j])) { count++; continue; } if (!isdigit(copy[j])) { count++; continue; } answer[j] = copy[j] - '0'; } // Print error if needed char copy2[100]; if (count != 0) { printf("You need to enter %d more digits to complete your guess\n", count); fgets(copy2, sizeof(copy2), stdin); // Loop through the second input and add it to the answer array for (int p = 0; p < 6; p++) { answer[p+count] = copy2[p] - '0'; } } // Print the contents of the answer array for (int d = 0; d < 6; d++) { printf("%d ", answer[d]); } return 0;}