Mail Archives: djgpp/1997/08/04/19:09:05

From: Mark Brown <M DOT A DOT Brown-4 AT sms DOT ed DOT ac DOT uk>
Newsgroups: comp.lang.c,comp.os.msdos.djgpp
Subject: Re: having trouble with long numbers
Followup-To: comp.lang.c
Date: 31 Jul 1997 23:15:52 +0000
Organization: Bah! Organization?
Lines: 58
Sender: broonie AT unknown DOT localdomain
Message-ID: <m3k9i6u82f.fsf@unknown.localdomain>
References: <01bc9c51$0ceeec80$78ed1fcc AT darkstar>
Mime-Version: 1.0 (generated by tm-edit 7.102)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

"Michèle C. Dupré" <forbinky AT ix DOT netcom DOT com> writes:

> I want to be able to have more than 10 digits print out (if the age were
> 10,000 years for example).

You want a variable capable of holding 10,000? The include file
limits.h defines the maximum values of various data types (among other
things). These must be at least the values specified in the
standard. For example, INT_MAX, the maximum integer value, must be at
least 32767. So this would hold 10,000 years OK.

> Also can someone direct me to the FAQ(so that I can RTFM)?

It can be ftped from in pub/usenet/comp.lang.c/ and found
on the web at . Most
newsgroup FAQs can be ftped from

> #include <stdio.h>
> int main()
> {
> int daysper, daystotal, secondsperday, years;
> long long totalseconds;
> daysper = 365;
> secondsperday = 86400;

These could be replaced by macros. For example

#define DAYS_PER 365
#define SECONDS_PER_DAY 86400

As you say below, this won't be completely accurate. There are leap
years to consider.

> printf("My second handmade program!\n\nTo tell you the number of seconds
> (estimate) you have lived.\n\n");

This would be easier to read as seperate lines. Also, you could use
puts() to print the text.

> printf("Enter your age in years: ");

fflush(stdout) would ensure that this gets written to screen. On some
implementations output is written a line at a time, and the prompt
wouldn't appear until the user typed return. fflush() is used on an
output stream (file) to ensure that everything that has been written
to it has been sent to the operating system.

> scanf("%d", &years);
> daystotal=(daysper * years);
> printf("Total days = %d\n\n", daystotal);
> totalseconds=(daystotal * secondsperday);
> printf("The total number of seconds is: %i\n",totalseconds);
>    return 0;
> }

- Raw text -

  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019