Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!husc6!rutgers!sri-spam!mordor!lll-lcc!ptsfa!ihnp4!homxb!mhuxt!mhuxm!mhuxo!ulysses!allegra!alice!ark From: ark@alice.UUCP Newsgroups: comp.lang.c Subject: Re: Big numbers in C? Message-ID: <7139@alice.UUCP> Date: Tue, 28-Jul-87 11:07:02 EDT Article-I.D.: alice.7139 Posted: Tue Jul 28 11:07:02 1987 Date-Received: Fri, 31-Jul-87 02:10:35 EDT References: <1192@killer.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 37 Keywords: big numbers In article <1192@killer.UUCP>, robertl@killer.UUCP writes: > I was wondering....How do I use large numbers (over 32000) in C? I know about > float type, but that give it in wierd numbers. I need numbers in the hundreds > of millions, and I need them in real format. (i.e. 100000000), not float > format. If there a little script that could change float to real? On most C implementations, the "long" type is stored as a 32-bit signed integer. That means you can store integer values between -2147483648 and 2147483647, inclusive. Is that big enough? A quick example: long foo; foo = 123456789L; printf ("%ld\n", foo); Notice the L at the end of the constant to say that it is a long number, and the %ld format item to print it. > Also, I am having a little trouble with this statement: > > strtol(data.number); > > Where: data.number[1] == 5 > data.number[2] == 7 /*Or whatever...Just examples*/ > data.number[3] == \0 When using something like strtol, the elements of the array you are converting should be representations of characters, not small integers. The following should work: data.number[0] = '5'; data.number[1] = '7'; data.number[2] = 0; /* or '\0' but not '0' */ Also note that subscripts in C start from 0, not 1.