Program : Not getting the desired output
Hi
For the following code i am getting double the actual result. For example if i enter 2 characters i get 4 as the output. #include <stdio.h> int main () { double nc = 0; /* count of entered characters */ while (getchar()!=EOF) { nc++; } printf ("The number of entered characters = %.0f",nc); return 0; } Note: This is how i enter the input when i execute the output file, because of getchar() it waits for input. I enter some character and press enter. Continues this until i press Ctrl-D (EOF in Unix). thanks, thelink |
Just out of curiousity, what happens, exactly, when you enter 3 characters?
|
Quote:
printf("The number of entered characters = %lf",nc); as datatype of nc is double it should not be called with float syntax(%f) instead use %lf |
I think you are typing incorrectly, perhaps hitting return or some such. Running your program typing ab followed by enough ctrl-d to get eof to work gives me 2 as the output.
|
Its Working
It is working now...The problem was with the incorrect input entry.
Thanks estabroo |
All times are GMT -5. The time now is 05:07 AM. |