Possible Duplicate:
void pointer as argument
I'm trying to make a simple function in C, but I get an empty output and I can't figure out why:
int encrypt(unsigned char *message, char *key, unsigned char *buffered_message) { /* ... */ buffered_message = calloc(1, (blocks * block_size)); /* ... */ printf("Message: %s\n", buffered_message); return strlen(buffered_message); } Inside the function, the message is printed out without problems. But when I try to use my function in main, something goes wrong.
int main() { /* ... */ unsigned char *encrypted; int len = encrypt(message, key, encrypted); if (len > 0) { printf("The encrypted message %s\n", encrypted); } return 0; }
buffered_message. Further duplicates: #1, #2, #3.unsigned char **.strlenlooks dodgy. The encrypted message may well contain null bytes. Since you're encrypting entire blocks anyway, there shouldn't be a need to communicate a string length, since the caller already knows the expected length.