Some of the examples in K&R don't work in Code:Blocks when I type them exactly. For example, this program:
#include <stdio.h>
main()
{
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
When I type this code and run it, the program either freezes or doesn't do anything when I press enter.
The program below does the same thing (count characters in a string) and it works.
#include <stdio.h>
int main()
{
char s[1000];
int i;
scanf("%s",s);
for(i=0; s[i]!='\0'; ++i);
printf("Length of string: %d",i);
return 0;
}
Am I missing something here? Has C been changed since K&R 2nd Edition or am I doing something wrong?