int changing on its own... Too Large?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lumpybanana247
    New Member
    • Apr 2007
    • 134

    int changing on its own... Too Large?

    in my script,
    a person is to type in the number 9999999999
    9999999999 is saved as file1 (works fine)
    9999999999 is loaded as integer1
    integer2 is set equal to integer1
    integer2 is saved as file2

    But,the thing is that file2 is "1410065407 " when it should be "9999999999 "

    file1 is how i wanted it (9999999999)

    is the number too big or somthing?
    how would it fix it?

    thanks for your help
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by lumpybanana247
    in my script,
    a person is to type in the number 9999999999
    9999999999 is saved as file1 (works fine)
    9999999999 is loaded as integer1
    integer2 is set equal to integer1
    integer2 is saved as file2

    But,the thing is that file2 is "1410065407 " when it should be "9999999999 "

    file1 is how i wanted it (9999999999)

    is the number too big or somthing?
    how would it fix it?

    thanks for your help
    On most systems an unsigned int can hold a number as large as 2^32-1.
    9999999999 % 2^32 == 1410065407 so yes, your ten digit 9s number is
    too large for an unsigned 32 bit integer. Try long long instead.

    kind regards,

    Jos

    Comment

    • lumpybanana247
      New Member
      • Apr 2007
      • 134

      #3
      neat, thank you very much- that explains a lot.
      is the only differnece that instead of declaring it
      int integer1;
      i use
      long long int integer1;
      because i tried it and it didnt work


      thank you!

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Originally posted by lumpybanana247
        neat, thank you very much- that explains a lot.
        is the only differnece that instead of declaring it
        int integer1;
        i use
        long long int integer1;
        because i tried it and it didnt work
        Did you do a sizeof(long long)?? You should get the size in bytes.

        For 32-bit Windows a long long is 8 bytes, which should be large enough.

        Comment

        • phiefer3
          New Member
          • Jun 2007
          • 67

          #5
          Originally posted by lumpybanana247
          neat, thank you very much- that explains a lot.
          is the only differnece that instead of declaring it
          int integer1;
          i use
          long long int integer1;
          because i tried it and it didnt work


          thank you!
          If I'm not mistaken you need to try:

          long long integer1;

          not long long int integer1;

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            This code:
            [code=c]
            long long int integer1;
            [/code]

            is perfectly OK. C (and C++) both allow you to code:
            [code=c]
            long long int integer1;
            short int var;
            //or
            long long integer1;
            short var;
            [/code]

            Comment

            • lumpybanana247
              New Member
              • Apr 2007
              • 134

              #7
              o, i get it.. THANKS

              Comment

              Working...