convert a uint8_t into char array

Hi everyone,
I have this function in my program

void adbEventHandler(Connection * connection, adb_eventType event, uint16_t length, uint8_t * data)
{
 
  int i;
  if (event == ADB_CONNECTION_RECEIVE)
    for (i=0; i<length; i++)
      Serial.print((char) data[i]);
}

and I want to convert the uint8_t *data into a string or char array to be able to compare it with a specific string. How can I convert it?

I already tried something like

char *input_cr;
input_cr=(char*) &data;
    Serial.println("Converted");
    Serial.print(input_cr);

but what I obtain is strange symbols at the line “Serial.print(input_cr);”. What am I doing wrong?

ps: sorry I am just novel in programming…

Don't covert it, just cast it:

uint8_t data[] = "Hello!";
int val = strcmp((char *) data, "Hello!");
input_cr=(char*) &data;

Ditch the reference symbol.

Arrch already gave you the answer, but just to reinforce his answer, try to think of something in memory as a bucket. For example, suppose you have the following definitions in your code:

int myNumber = 10;
int val;
int *ptr;

And imagine that the compiler puts myNumber at memory address 500, which is also called its lvalue (i.e., location value). If we go to memory address 500 and look inside, we see the value of 10, also called its rvalue (i.e., is register value). The data type specifier (int) in the statement tells you the data item's size; it's a 2-byte bucket. Now consider:

ptr = &myNumber;
val = *ptr;

The address of operator (&) in front of myNumber tells you that the bucket is located at memory address 500, so the statement places 500 in the variable ptr as its rvalue. After all, a valid pointer can only hold a memory address or null, not a normal data value. The indirection operator (*) says: "Goto to the memory address stored in ptr's rvalue (500), and fetch what you find there." Since ptr is an int pointer, the compiler knows to grab two bytes from address 500 and move those bytes into the rvalue of val.
In your code, by having the address of operator in from of data, you were telling the compiler to treat the byte stored at data[0] as a memory address, rather than a pointer to some data. That's why the compiler was complaining.

Thanks both :slight_smile: That fixed my problem.

I actually have a question though. The value passed in the function is uint8_t * data, in which data is a memory location. So why Serial.print((char) data*) prints the content of that memory location?*

brok:
Thanks both :slight_smile: That fixed my problem.

I actually have a question though. The value passed in the function is uint8_t * data, in which data is a memory location. So why Serial.print((char) data*) prints the content of that memory location?*
[/quote]
That isn't what you are printing, this is your actual code:
* *Serial.print((char) data[i]);* *
While data is pointer data[i] is not a pointer, it is the value of what is stored at data[i]
--- bill