I have this program and I want it to increment by one and print the value of my counter each time I give a character
#include <stdio.h> int main(void){ //Declarations long nc; //Instantiations nc = 0; while (getchar() != EOF){ ++nc; printf("%ld\n", nc); } return 0; } When the loop initiates if I press ENTER I get 1,2,3,4,5... which is ok.But if I type a character or something else it prints the next two numbers 12,34,56,78. Why is that happening??
I am running the program on gcc 4.6.3 Ubuntu 12.04 release.