c - why it doesn't print the result?(I've already tapped ctrl+z(windows10) after the input) -


why doesn't print result? i've tapped ctrl+z after input.

code:

#include <stdio.h> /*histogram of frequences of chars*/ main() {     int charin, numa, numb;     numa = numb = 0 ;     while ((charin == getchar()) != eof)     {         if (charin =='a')             ++numa;         if (charin =='b')             ++numb;      }     printf("a:%d\n",numa);     printf("b:%d\n",numb); } 

loop running infinitely. change

while ((charin == getchar()) != eof) 

to

while ((charin = getchar()) != eof)   

also note using charin before initialization in (charin == getchar()) , invoke undefined behavior.


Comments