I am just starting to learn C, this is probably a very easy question for you guys but your help is very appreciated. I am trying to use this code to count the number of characters inputted into the console but when I hit enter it just gives me a blank new line, like printf hasn’t worked. Where am I going wrong?
int c, number;
while((c = getchar()) != EOF){
++number;
}
printf("%d\n", number);
Thanks.
When you hit enter, the program increments the counter because it gets a newline character and waits for more input. You have to feed the program an EOF with Ctrl+D (Linux, Unix, Mac) or Ctrl+Z, Enter (Windows).