Thread: MD5 with variables in C

  1. #1
    Registered User
    Join Date
    Apr 2009

    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:

    In the md5.c it has a test variable as below.
    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).

    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,

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

    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, 12:02 PM
  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, 11:07 PM
  5. Craps Program with Local Variables
    By tigrfire in forum C Programming
    Replies: 12
    Last Post: 11-09-2005, 09:01 AM