C Function Problem

03/05/2013 19:46 Kingrap#1
Hi community,
today i convert C++ function to C for my friend..

this is C++ function

Code:
std::string decrypt(std::string str,int size)
{
    std::string decrypted_string;

    for (int i = 0; i < size; i++) { decrypted_string += str[i] - 0xF ^ 0xC3; }

    return decrypted_string;
}
and this is the function in C

Code:
char *decrypt(char *packet, int size)
{
     char *decrypted;
     for(int i = 0; i < size; i++)
     {
           decrypted[i] = packet[i] - 0xF ^ 0xC3;
     }
     return decrypted;
}
i use function C in this mode..

Code:
char recvdata[255];
int bytes = recv(client,recvdata,255,0);
char *data = decrypt(recvdata,bytes);
printf("%s",data);
i don't know because this don't work.. è.é

error: 0xC0000005 Access violation in writing of location 0xC0000000.

help me please :rolleyes:
03/05/2013 19:57 snow#2
Where does ist crash? If it's within your decrypt-Function:

Try allocating the memory for your char-Pointer:
char *decrypted = (char *)malloc(size * sizeof(char));
03/05/2013 20:13 MrSm!th#3
Of course it crashes. decrypted is not a valid pointer.
03/05/2013 21:12 Kingrap#4
thanks now it work :)