9uzman7
9uzman7

Reputation: 488

C++ cast char * to unsigned char

I am working in a c++ project where I have to use < openssl/sha.h> and I am using in particular the SHA1 function. My problem is, that the function receives unsigned char[], and I need to get processed parameters passed as arguments to the program:

int main(int argc, char* argv[])
{

  unsigned char message[] = argv[1];

  /* program continues using message */

}

And the error I am getting is the following:

error: array initializer must be an initializer list or string literal
const unsigned char message[] = argv[1];
                    ^

So I am not getting to cast appropiately the argument input to the 'message' variable, to make the appropiate call to SHA1 function.

Thanks!!

Upvotes: 0

Views: 3482

Answers (1)

Sam Varshavchik
Sam Varshavchik

Reputation: 118425

An array cannot be initialized from a pointer. You should probably use an unsigned char * instead:

unsigned char *message = reinterpret_cast<unsigned char *>(argv[1]);

Upvotes: 2

Related Questions