It seems my implementation of fgets() is incorrect here, would very much appreciate some extra eyes to look over what I've done!
Here's the code
int main(int argc, const char* argv[]){ int numIntegers; char buffer[20]; int intArray[10]; //if no argument is passed in, terminate if (argc == 1){ printf("no argument given, terminating..\n"); return EXIT_FAILURE; } else{ numIntegers = atoi(argv[1]); //we only want numbers greater than 0 if (numIntegers <= 0){ printf("# must be greater than 0\n"); return EXIT_FAILURE; } else{ printf("Enter %d integer values to place in array: \n", numIntegers); for (int i = 0; i < numIntegers; i++){ fgets(buffer, numIntegers, stdin); intArray[i] = atoi(buffer); printf("Index is = %d \n", i); } } } //for (int i =0; i < numIntegers; i++){ // printf("Index[%d] = %d \n", i, intArray[i]); //} } Here's the output, the line with no other text besides an integer is user input. Notice how the value of i resets. The issue only occurs when I give an initial argument of anything more than 10. It turns the for loop into an endless loop, for whatever reason.
$ ./a.out 11 Enter 11 integer values to place in array: 5 Index is = 0 2 Index is = 1 1 Index is = 2 2 Index is = 3 3 Index is = 4 4 Index is = 5 123 Index is = 6 123 Index is = 7 123 Index is = 8 1 Index is = 9 2 Index is = 2 2 Index is = 3 3 Index is = 4 5 Index is = 5 1 Index is = 6 12 Index is = 7