Assigning large value

This is a discussion on Assigning large value within the C Programming forums, part of the General Programming Boards category; hi i m new here!! now i got a problem ... I need a number not less than 13digits to ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    5

    Assigning large value

    hi i m new here!! now i got a problem ... I need a number not less than 13digits to assign to a variable. which data type should i use? i tried, (it might be wrong), "long long int " n still i got stuck!! help me out

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    long long int will gladly handle numbers above 13 digits.
    If it does not work, then show us your code and tell us what compiler you use.
    Also try
    printf("%d", sizeof(long long int));
    and tell us what it prints.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jun 2003
    Location
    Austria
    Posts
    55
    a long long int contains 64bit so there is a number range of 9223372036854775807 to -9223372036854775807.
    13 digits shouldn't be problem for long long int.

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    5
    i m using gcc v4.1.2. and my piece of code is like this
    <code>
    long long int x= 13131313131313;
    printf("%lld", x); // have also tried %ld.
    </code>

    And sizeof says 8.
    Last edited by HzTzr; 02-13-2009 at 07:14 AM.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Code:
    #include <stdio.h>
    
    int main()
    {
    	unsigned long long ll = 0xFFFFFFFFFFFFFFFF;
    	printf("%llX\n", ll);
    	return 0;
    }
    Output: FFFFFFFFFFFFFFFF

    Code:
    #include <stdio.h>
    
    int main()
    {
    	unsigned long long ll = 0xFFFFFFFFFFFFFFFF;
    	printf("%llu\n", ll);
    	return 0;
    }
    Output: 18446744073709551615
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Feb 2009
    Posts
    5
    I m so sorry for my stupidity!!! actually i am using lots of C compiler. I am currently using Dev-C++ 4.9.9.2 and i found out that it uses gcc v3.4.2 (mingw-special). (Sorry for losing your time). I tried your last code with this compiler and it prints 4294967295. help me out !!!!

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That is becasue gcc-mingw uses an older C-library, so the printf format for long long is "%I64d" rather than "%lld".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Feb 2009
    Posts
    5
    Thank you very much!!! It works .... but may i know what is this "%I64d"... where can i learn more about format specifiers??? Thank you!!

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by HzTzr View Post
    Thank you very much!!! It works .... but may i know what is this "%I64d"... where can i learn more about format specifiers??? Thank you!!
    You may want to have a look here:
    http://msdn.microsoft.com/en-us/libr...dc(VS.71).aspx

    for example. Since gcc-mingw is using Microsoft's C library, the relevant generation of the MSDN documentation is what you need - I'm not sure if that's the exact right version, but it's at least 99% right.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    Feb 2009
    Posts
    5
    Thanks again... a LOT Mr. Kernel hacker !! n many thanks to Elysia too!!! I m feeling much better now!!!

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Strange that gcc would not support "standard" format specifiers? At least I believe they are standard.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Elysia View Post
    Strange that gcc would not support "standard" format specifiers? At least I believe they are standard.
    gcc disclaims all responsibility for msvcrt.dll (or whatever it's called these days).

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    But MS's printf DOES support llx or llu (the newer versions).
    So if GCC uses an old library, then I blame GCC.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,743
    Quote Originally Posted by Elysia
    Strange that gcc would not support "standard" format specifiers? At least I believe they are standard.
    In C99, yes. HzTzr, compile your program with the -std=c99 option.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    But MS's printf DOES support llx or llu (the newer versions).
    So if GCC uses an old library, then I blame GCC.
    Only because the gcc-mingw maintainers hasn't produced a (stable) version of gcc-mingw for later versions than 3.4.x. But of course, it is still not GCC's fault for what is in a third party library, any more than it is the fault of a game that a particular implementation of OpenGL causes bad drawing on particular models of graphics card, right?

    After all, the COMPILER can not fix the libraries it links to.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [Large file][Value too large for defined data type]
    By salsan in forum Linux Programming
    Replies: 11
    Last Post: 02-05-2008, 03:18 AM
  2. Computing Large Values
    By swbluto in forum C++ Programming
    Replies: 8
    Last Post: 04-07-2005, 03:04 AM
  3. Representing a Large Integer with an Array
    By random_accident in forum C Programming
    Replies: 3
    Last Post: 03-03-2005, 07:56 PM
  4. Representing a Large Integer with an Array
    By random_accident in forum C++ Programming
    Replies: 3
    Last Post: 03-03-2005, 11:23 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