|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
old code troubles
The book I am using - "The C Programming Language (second edition)" was written in 1988 so I am presuming that reason this isnt working is because it is so old =\ -
Code:
#include <stdio.h>
/* count characters in input; 2nd version */
main()
{
double nc;
for( nc = 0; getchar() != EOF; ++nc )
;
printf("%.0f\n", nc);
}
or this one: Code:
#include <stdio.h>
/* count characters in input; 1st version */
main()
{
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
any help into why this isnt working - so that I can take not of it for other code in this book - would be greatly appriected =) |
|
#2
|
|||
|
|||
|
What do you mean "isnīt working"?
If you run the compiled program and it just does not end waiting for input, you have to press "CTRL-D" (CTRL-Z for Win/Dos). this is the EOF getchar() it is waiting for... The book you refer to, is this the "Kernighan & Ritchie"? then it IS valid since they invented the C language. It should say "ANSI C" on the title too for the second (and up to date) edition. I learned C with this book and i can tell you, it is quite good! (Mine is from 1988 too) I guess your compiler is not compatible. Which one do you use? And which OS do you write your code on? A lot of stuff does not work eg. for MS-DOS, since DOS is crap... Same for Win9X-ME. Use Linux and GCC. IMHO Itīs your best choice for learning C.
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. |
|
#3
|
|||
|
|||
|
Yeah the book is the K&R one and looks great so far and im using Dev-C++4 on Win2k - oh and ctrl+Z works thanks =)
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > old code troubles |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|