i am working on a c programming book.
The C Programming Language by
Brian W. Kernighan and Dennis M. Ritchie
there is a program for counting characters.
i called the program prog1.5.2.c i will include it here:
the book calls it a character counting program.
the program compiled without any errors, but when i went to run it it didn't seem to do anything but return a blank line.
does anyone no what went wrong?
there is also another way to write the above program using a for loop instead of while. i will list it here i called the c source file program prog1.5.2a.c
again the program compiled but didn't seem to count characters.
any help would be appreciated.
The C Programming Language by
Brian W. Kernighan and Dennis M. Ritchie
there is a program for counting characters.
i called the program prog1.5.2.c i will include it here:
Code:
#include <stdio.h>
/* count characters in input; 1st version */
main()
{
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
the book calls it a character counting program.
the program compiled without any errors, but when i went to run it it didn't seem to do anything but return a blank line.
does anyone no what went wrong?
there is also another way to write the above program using a for loop instead of while. i will list it here i called the c source file program prog1.5.2a.c
Code:
#include <stdio.h>
/* count characters in input; 2nd version */
main()
{
double nc;
for (nc = 0; getchar() != EOF; ++nc)
;
printf("%.0f\n", nc);
}
again the program compiled but didn't seem to count characters.
any help would be appreciated.