Click here to Skip to main content
15,847,903 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to convert char *aa="test" to unsigned char[]={0x74 ,0x65 ,0x73 ,0x74} in C

As already noted, a simple cast is enough.
Please note aa should be declared const char *.

#include <stdio.h>

int main()
  const char * aa = "test";
  const unsigned char * bb = (const unsigned char *) aa;

  while ( *bb )
    printf("%02X ", *bb++);


  return 0;
Share this answer
You asked for C so the cast is C. cout is easier than printf to show contents of array.

#include <iostream>
#include <conio.h>
#include <iomanip>

using namespace std;

int main()
char *aa="test";

unsigned char *bb = (unsigned char*) aa;

 int n = 0;

	 cout << hex << (int) bb[n] << endl;

return 0;
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900