I am reading over the K&R book, and am a little stuck.
What is wrong with the following?
void getInput(int* output) {
int c, i;
for(i=0; (c = getchar()) != '\n'; i++)
output[i] = c; // printf("%c", c) prints the c value as expected
output[++i] = '\0';
}
When I run the program it never gets out of the loop and I have to Ctrl+C to exit. However if I replace the fifth line with printf("%c", c);
, it prints out all the input just fine after hitting enter and creating the new line.