I have the following code from Kernighan & Ritchie’s book:
#include <stdio.h>
int main() {
int c, nl;
nl = 0;
while((c = getchar()) != EOF)
if (c == 'n')
++nl;
printf("%dn", nl);
return 0;
}
I understand how it works and what should it do in theory. What I don’t understand is, what’s happening in reality.
When I run the program (on windows) and write some text that consists of two lines for example, then I press ctrl z, the progrem completely closes itself. I don’t understand where or how should it show me the lines my text contained.
I would gladly appreciate some help or explanation.
Thank You in advance!
I expected the program to show me the number of lines in a text. In reality, it just closes itself.
Bence Sárközi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5