Thread: Accepting large integers as entry

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    50

    Red face Accepting large integers as entry

    I need to accept large intger of say 15 digits. how to do that except using array?
    even if i use array, can i use getw() for accepting the whole number at one turn but storing the digits at different positions at array(i.e. one digit in each room of array) ? is there any other way?

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Try using the GNU MP Bignum Library....

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Sooner or later, you'll need an array of some sort.

    Use fgets() to read your string of digits into a char array, and then you can do whatever you want with it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Abhas View Post
    I need to accept large intger of say 15 digits. how to do that except using array?
    even if i use array, can i use getw() for accepting the whole number at one turn but storing the digits at different positions at array(i.e. one digit in each room of array) ? is there any other way?
    in Pelles C....
    Code:
    // native type
    unsigned long long int  number;
    
    
    // alternative method
    #include <stdint.h>
    
    uint64_t number;
    That produces an unsigned 64 bit integer that will go 18 digits... as in > 999,999,999,999,999,999.

    Check the help file, it's all there...

  5. #5
    Registered User
    Join Date
    Jul 2007
    Posts
    131
    Quote Originally Posted by CommonTater View Post
    in Pelles C....
    Code:
    // native type
    unsigned long long int  number;
    
    
    // alternative method
    #include <stdint.h>
    
    uint64_t number;
    That produces an unsigned 64 bit integer that will go beyond 18 digits... as in > 999,999,999,999,999,999.

    Check the help file, it's all there...
    In STANDARD C, that creates an unsigned 64-bit integer which has values 0-2^64-1. It isn't only Pelles C's feature, and your description of the value range was very vague.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    1) I know the OP is using Pelles C... now this setup comes with one really great help file (and practically everything else you need) so I spoke to him in that context.

    2) Pelles C adheres very closely to the C-99 standard and all extensions and exceptions are well documented.

    3) His question was how he could get a 15 digit number... that usually means between 0 and 999,999,999,999,999 to most people and calculators. I gave him a data type that would accomodate that range, noting that it goes well beyond his needs as well.

    Really... Why, exactly, do you think that's a problem?
    Last edited by CommonTater; 04-10-2011 at 09:22 AM. Reason: incredulity.

  7. #7
    Registered User
    Join Date
    Apr 2011
    Posts
    50
    everyone lots of thanks. that solves my problem.

  8. #8
    Registered User
    Join Date
    Jul 2007
    Posts
    131
    Quote Originally Posted by CommonTater View Post
    1) I know the OP is using Pelles C... now this setup comes with one really great help file (and practically everything else you need) so I spoke to him in that context.
    IMO you gave an image that it is specific to Pelles C, which is wrong, and in that case it should've been noted that it isn't standard way.

    2) Pelles C adheres very closely to the C-99 standard and all extensions and exceptions are well documented.
    Your point here is...?

    3) His question was how he could get a 15 digit number... that usually means between 0 and 999,999,999,999,999 to most people and calculators. I gave him a data type that would accomodate that range, noting that it goes well beyond his needs as well.
    IMO your information was lacking. In this type of case, in my opinion it's better to explain the situation accurately, so the person who asked know in the future if that solution works in some other case, and if in fact he had meant e.g.numbers between -10^16 and 10^16, he would've notices more certainly that this doesn't suit his needs (I know he would've spotted unsigned ...).

    Really... Why, exactly, do you think that's a problem?[/QUOTE]

  9. #9
    Registered User
    Join Date
    Apr 2011
    Posts
    50
    hey 1 more thing thing: how to print or scan it??? i mean printf("%what??")

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Abhas View Post
    hey 1 more thing thing: how to print or scan it??? i mean printf("%what??")
    Look up printf() in your PellesC help file... Better still, in the source editor put your cursor on the word printf and press F1...

    Really... you have an extremely well documented compiler there... learn to use it!

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    It would be "%lld" or "%llu" depending on sign.

    You might want to start reading though some standards, to see what's actually available (or even other online reference manuals).
    C Draft Standards
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  12. #12
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Salem View Post
    It would be "%lld" or "%llu" depending on sign.

    You might want to start reading though some standards, to see what's actually available (or even other online reference manuals).
    C Draft Standards
    Salem... if you never do anything else with Pelles C... please take a cruise through the help file...

    abhas has all that right at his fingertips, all he has to do is click "Help" or press F1.

    There are C language definitions, complete library documentation, IDE instructions, compiler documentation, even a bunch of "handy extras" like ASCII charts... I'm not kidding when I say it is VERY complete. When I'm not working winapi it is rare indeed that I need any other documentation than that provided in the help file.

    No... I am NOT saying he should not look elsewhere (but you already knew that) I am simply suggesting that he should learn to use the resources he already has.

  13. #13
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by fronty View Post
    IMO your information was lacking. In this type of case, in my opinion it's better to explain the situation accurately, so the person who asked know in the future if that solution works in some other case, and if in fact he had meant e.g.numbers between -10^16 and 10^16, he would've notices more certainly that this doesn't suit his needs (I know he would've spotted unsigned ...).

    Really... Why, exactly, do you think that's a problem?
    Think about this in context... no.... really think about it before you hit reply.

    If someone asked you a question about an 9 foot 2x4 how well do you think your answer would be understood if you responded in terms of a 3 meter 6X11? You may have been technically accurate in your response...spot on, in fact... but how helpful was it?

    He asked a question where there were two important contexts...
    1) Pelles C's data types... (He's just upgraded from an older compiler that lacks C-99s features)
    2) The number of decimal digits (15)...

    I merely responded within those contexts...

    Now please note... the button is marked "reply"... not "argue".
    Last edited by CommonTater; 04-10-2011 at 11:53 AM.

  14. #14
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by whiteflags View Post
    In response to that, I have to ask if it makes clear what is standards conforming, and what is not? If so it would be the first example of compiler documentation I know that does.

    Of course, I'm assuming abhas doesn't have a standard reference online or elsewhere. If he does, all he has to do is cross-reference it with the standard.
    How's this... from the help file...
    _clrscr function [not standard C] [4.00]

    Purpose:
    Clears the console screen.

    Syntax:
    void _clrscr(void);

    Declared in:
    <conio.h>

    Description:
    The _clrscr function clears the console screen using the current background color and then moves the cursor to the top, left position.

    Returns:
    Nothing
    The first line quoted as seen in the help file is dark blue on light blue the "[not standard C]" is blood red so it's hard to miss and the number at the end is the version of the compiler where the function first appeared.

    Attachment 10489



    Moreover the libraries section of the help file itself is split into two sections...
    "Standard C99 #include files" and "Private #include files"...

    So yes it very clearly identifies standard and non-standard functions.
    Last edited by CommonTater; 04-10-2011 at 01:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Large integers multiplications
    By ahmedBanihammad in forum C Programming
    Replies: 3
    Last Post: 03-27-2011, 12:23 PM
  2. Storing and printing large integers
    By newbie123 in forum C Programming
    Replies: 8
    Last Post: 09-16-2010, 01:17 PM
  3. Messing with Large Integers
    By johnnie2 in forum Windows Programming
    Replies: 3
    Last Post: 11-16-2002, 01:22 PM
  4. accepting large amounts of data
    By Sekti in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2002, 05:45 PM
  5. Storing large integers....why doesn't this work?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 09-21-2001, 09:41 PM