We like to help those that show some effort, especially when it appears to be an assignment.
Show us what you've tried. Tell us what it does and what you expected it to do and we can help you make the two match up better.
(I wouldn't be surprised to find an example program kicking around here somewhere...did you do a search before you started a topic?)
Murtan
Practically a Master Poster
671 posts since May 2008
Reputation Points: 344
Solved Threads: 116
That looks like it ought to work.
The program is counting the characters in the word say "daniweb" and also counting the enter as it is also a character before the EOF.
if you entered "daniweb" ctrl+d enter, it should count 7.
Murtan
Practically a Master Poster
671 posts since May 2008
Reputation Points: 344
Solved Threads: 116
sorry i forgot to post my code
#include <stdio.h>
int main() {
int i ;
int c;
while ( ( i = getchar() ) != EOF )
c++ ;
printf( "%d characters\n" , c) ;
return 0;
}
does this seem ok? ... when i run it ./a.out i click enter
then i enter a word say "daniweb" and press enter and then hit ctrl+d and it says 8 characters
where is c initialized ?
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608