I have a simple error that I know lies underneath my C code's memory usage, because the iterator in a simple for loop changes drastically after receiving user input on the command line:
int i = 1;
char input[] = "";
for (i = 1; i <= 5; i++) {
printf("i %d\n> ", i);
scanf("%s", input);
printf("input %s\ni %d\n", input, i);
}
The output should be simple enough:
i 1
> <receive input>
input <input>
i 1
to be repeated 5 times.
However, the iterator 'i' changes to anything but what is expected when any input is received.
An example output:
i 1
> 45
input 45
i 53
I have a hunch that this comes from memory access in the compiler. Anything helps!