C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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 October 8th, 2002, 01:15 AM
empty empty is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Australia
Posts: 9 empty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to empty Send a message via AIM to empty
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 =)

Reply With Quote
  #2  
Old October 8th, 2002, 12:45 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
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.

Reply With Quote
  #3  
Old October 9th, 2002, 01:19 AM
empty empty is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Australia
Posts: 9 empty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to empty Send a message via AIM to empty
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 =)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > old code troubles


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway