MD5 with variables in C

This is a discussion on MD5 with variables in C within the C Programming forums, part of the General Programming Boards category; Hi all, I'm wanting to use MD5 in C and have found the following md5.c file along with the md5.h: ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    1

    MD5 with variables in C

    Hi all,

    I'm wanting to use MD5 in C and have found the following md5.c file along with the md5.h:
    http://cr.yp.to/2004-494/gaim/0.81-src/md5.c

    In the md5.c it has a test variable as below.
    Code:
    static const char *const test[7] = {
    "12345678901234567890123456789012345678901234567890123456789012345678901234567890" /*57edf4a22be3c955ac49da2e2107b67a*/
        };

    I wish to change this test variable to accept numbers, so that I can keep generating MD5 of a variables like below (I don't have the exact code infront of me, but this is what I can remember that I did).

    Code:
    long myvar = 1283781913;
    char *my_str = "";
    sprintf(mystr, "%li", myvar);
    static const char *const test = my_str;
    It compiles but it gives wrong results. If I do static const char *const test = "1283781913", it gives the correct results.

    Is there something wrong with my code or could anyone offer any assistance.

    Thank you,
    Alex.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    my_str doesn't actually point to any allocated data. Use an array, or use malloc to allocate space.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Best way to avoid using global variables
    By Canadian0469 in forum C++ Programming
    Replies: 7
    Last Post: 12-18-2008, 11:02 AM
  3. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  4. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 10:07 PM
  5. Craps Program with Local Variables
    By tigrfire in forum C Programming
    Replies: 12
    Last Post: 11-09-2005, 08:01 AM

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