Currently stuck trying to break the for loop once all the space separated have been captured. I've spent over an hour on all sorts of pages and my code looks identical to what I've been finding on other articles however. scanf() != EOF never eventuates in my code.
int readInput(unsigned char input[], size_t inputMaxLength)
{
int size = 0; // We want to return the length of the string
for ( int i = 0; i < inputMaxLength ; i++) { // We only want to capture n amount of chars
if (scanf("%hhu", (input + i)) != EOF) { // input + i to iterate through the input array
printf("i = %d , Read %d\n", i , *(input + i));
size++;
} else {
return size; // this never occurs which means scanf never == EOF
}
}
return size;
}
output looks like so,
12 65 98 45 44
i = 0 , Read 12
i = 1 , Read 65
i = 2 , Read 98
i = 3 , Read 45
i = 4 , Read 44
Unfortunately, size is never returned by this function and the script is left waiting for further input. Also, it is a constraint that i must use scanf to capture inputs for this function.