Hello everyone, I'm new to C and want to learn more about it. My main learning source is the (ANSI) C Programming Language 2nd ed. book by Brian Kernighan and Dennis Ritchie. As for previous programming experiences, I've dabbled a bit in Visual Basic and Maple.
My main issue began when I started working on the chapter that deal with getchar() and EOF parameters. The book listed several example code that use getchar() to read and count the number of characters, lines, and words from input.
So I began using these codes and compiled it with Visual Studio 2008 Command Prompt (under Windows 7) without any syntactical issues. However, when I open my .exe and test it, I was surprise that no matter how many times I enter in any letters or numbers, the program did not count and print the expected value. I've double checked everything, copy and paste codes exactly, went on several different sites and test different versions of codes, run program under winxp, nothing have yet to provide my desired result. Here is an example of one variation which counts the number of characters from an input:
So either I am confused about what these codes suppose to do or there is some special command that I am missing. I really hope someone can help me. I am beginning to love C and don't want to be stuckCode:#include <stdio.h> void main() { int c, nc = 0; while ( (c = getchar()) != EOF ) nc++; printf("Number of characters in file = %d\n", nc); }