Like Tree1Likes
  • 1 Post By Salem

Integer constant is too large for 'long' type. How do I fix it?

This is a discussion on Integer constant is too large for 'long' type. How do I fix it? within the C Programming forums, part of the General Programming Boards category; Hi, so I'm trying to make a program that will display the digits of up to a maximum of 10 ...

  1. #1
    Y2R
    Y2R is offline
    Registered User
    Join Date
    Feb 2012
    Posts
    12

    Integer constant is too large for 'long' type. How do I fix it?

    Hi, so I'm trying to make a program that will display the digits of up to a maximum of 10 digit number in column form. I used "long long int" since it's a huge number. And for my printf and scanf I used "%lld". I get an error pointing at my 'for loop' line saying "Integer constant is too large for 'long' type". I use Quincy on Windows 7. Here is the code:

    Code:
    #include <stdio.h>
    main ()
    {
        long long int n;
        long long int digit;
        long long int i=10,j=1;
        
        printf ("Enter a positive integer up to a maximum of 10 digits: ");
        scanf ("%lld",&n);
        printf ("\n");
        
        for (i;i<=10000000000;i*=10)
        {
            digit=(n%i)/j;
            printf ("%lld \n",digit);
            j*=10;
        }
    }
    Thanks!

  2. #2
    Y2R
    Y2R is offline
    Registered User
    Join Date
    Feb 2012
    Posts
    12
    Also, it all works well, if I change the limit for i to 1 and 9 zeroes. If I do 10 zeroes, I get the error

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,418
    Try writing
    for (i;i<=10000000000LL;i*=10)
    Y2R likes this.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Y2R
    Y2R is offline
    Registered User
    Join Date
    Feb 2012
    Posts
    12
    Whoah! Siiick! Thanks a lot!
    We haven't learn any of this in class, but that was the problem. Works well
    Thank you so much!

  5. #5
    Registered User
    Join Date
    Nov 2011
    Location
    Douala, Cameroon
    Posts
    187
    @y2r another option is to use and array to store the characters and then accessing the characters the way u want.

  6. #6
    Y2R
    Y2R is offline
    Registered User
    Join Date
    Feb 2012
    Posts
    12
    Quote Originally Posted by Nyah Check View Post
    @y2r another option is to use and array to store the characters and then accessing the characters the way u want.
    Oh yeah, I've heard of arrays. This friend of mine always talks about that, but we haven't studied them yet in class. But when I learn it, then it would be much easier I would assume. Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. on 16-bit system long will guarantee 4-bit integer type?
    By jackson6612 in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2011, 10:45 AM
  2. Replies: 1
    Last Post: 10-11-2010, 01:53 AM
  3. Replies: 7
    Last Post: 06-01-2008, 07:47 AM
  4. integer constant is too large for type
    By Abda92 in forum C++ Programming
    Replies: 8
    Last Post: 02-09-2008, 10:47 AM
  5. is there an infinitely large integer type?
    By MKashlev in forum C++ Programming
    Replies: 7
    Last Post: 08-10-2002, 02:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21