October 8th, 2002, 02:15 AM
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 =\ -
or this one:
/* count characters in input; 2nd version */
for( nc = 0; getchar() != EOF; ++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 =)
/* count characters in input; 1st version */
nc = 0;
while (getchar() != EOF)
October 8th, 2002, 01:45 PM
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.
October 9th, 2002, 02:19 AM
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 =)