![]() |
| | #1 |
| Registered User Join Date: Feb 2010
Posts: 30
| Code: #include <stdio.h>
main()
{
long nc;
nc = 0;
while(getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
|
| metros is offline | |
| | #2 |
| Registered User Join Date: Dec 2009 Location: Henderson, NV
Posts: 532
| Ugh, formatting... Code: #include <stdio.h>
main()
{
long nc;
nc = 0;
while(getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
As for your question here is a hint: EOF != '\n' (or maybe '\r' depending on platform) |
| jeffcobb is offline | |
| | #3 |
| critical genius Join Date: Jul 2008 Location: SE Queens
Posts: 5,173
| Because pressing return does not indicate EOF. Try using: Code: while(getchar() != '\n') |
| MK27 is online now | |
| | #4 |
| Registered User Join Date: Feb 2010
Posts: 30
| Thanks all. One more thing..... when the program is running, how do I escape back to normal terminal node? |
| metros is offline | |
| | #5 |
| Registered User Join Date: Dec 2009 Location: Henderson, NV
Posts: 532
| Well, once you escape your while() loop with either CTRL-D (EOF) or ENTER ('\n') it should print the number of characters and exit for you... |
| jeffcobb is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compiling Program as .exe with no dependancy on other files | nitesh | C++ Programming | 2 | 11-01-2009 09:54 AM |
| How can I make this code more elegant? | ejohns85 | C++ Programming | 3 | 04-02-2009 08:55 AM |
| New string functions | Elysia | C Programming | 11 | 03-28-2009 05:03 AM |
| OpenGL Window | Morgul | Game Programming | 1 | 05-15-2005 12:34 PM |
| fopen(); | GanglyLamb | C Programming | 8 | 11-03-2002 12:39 PM |