-
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.
-
my_str doesn't actually point to any allocated data. Use an array, or use malloc to allocate space.
Quzah.