problem after converting int to char

This is a discussion on problem after converting int to char within the C Programming forums, part of the General Programming Boards category; i converted the following ints into unsigned chars using sprintf as follows: int x = 1, y = 2, z ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    1

    Unhappy problem after converting int to char

    i converted the following ints into unsigned chars using sprintf as follows:

    int x = 1, y = 2, z = 3;
    unsigned char partIn[10];
    sprint f (partIn, "%d,%d,%d", x,y,z);

    once conversion is complete 'partIn' is inserted into the following function:

    R_SignUpdate (&context, partIn, partInLen);

    This function uses a helper function:

    MD5_DigestUpdate(context,partIn,partInLen) to calculate a message digest using the integers specified in partIn as "x, y and z".

    There is a second function under the same main argument:

    R_VerifyUpdate (&context, partIn, partInLen);

    This function also uses the same helper function:

    MD5_DigestUpdate(context,partIn,partInLen) to calculate a message digest using the integers specified in partIn as "x, y and z".

    THE PROBLEM:
    Both functions produce different message digests eventhough i pass on the same 'partIn' with the same converted integers.

    Why does it give two totally different values when the same formula is used with the same input arguments???

    Please any immediate help would be deeply appreciated. this cde is part of my MSc project and the deadline is getting closer !!

    Regards,
    ise152

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> i converted the following ints into unsigned chars using sprintf...

    that statement is somewhat imprecise - to 'convert' practically implies casting, which is not what you have done - copied the integers into a character array would be a better description. anyway, there isn't any reason to use an array of unsigned chars here (unless your digest functions require it, of course) - alphanumeric data does just fine in a plain old array of chars. as far as your bug, I'd say it's probably in the digest functions themselves. hard to say though without seeing more code...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. C problem with legacy code
    By andy_baptiste in forum C Programming
    Replies: 4
    Last Post: 05-19-2008, 06:14 AM
  3. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. Replies: 1
    Last Post: 10-27-2006, 01:21 PM

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