Getting address of a char array using pointer

Hello, before posting this, i have searched on this forum a solution to the problem i have. Unlucky, i haven't found yet.

Why i am here? Why do i need? Of course, it's your help on the next thing.

I am creating a char variable with 5 position like this: "char t[4];". Next, i'm assigning char values in each index of the variable. Then, i am creating a pointer variable to save the direction of the first element of t. Finally, i want to check the address but it gave me an error like this: "cannot convert 'char*' to 'int*' in assignment". I think, i'm doing bad assigments but not really sure.

My question is: ¿How can i get the address of a char array?

Gonna post the code above.

Thanks for your attention.

void loop() {
  char t[4];
  t[0] = '3';
  t[1] = '4';
  t[2] = '.';
  t[3] = '1';
  t[4] = '5';
  int* ptr_t;
  ptr_t = &t[0];
  Serial.print("La direccion del apuntador es: ");
  Serial.println(ptr_t);
delay(2000);
}

A pointer to the first element of t is t, but it is a char pointer, not an int pointer.

Would be so kind if you can write how to print correctly the address.

Thanks

Why not cast the pointer to an int, and print the value of the int?

void * is the generic pointer type, use that instead of the int *.

Also char t[4] only creates an array of length 4, with elements 0,1,2 and 3. You want a length of 5 if you want t[4] to exist.

If you want to print a character array (as a "C-string"), the last element of t[] must contain 0 as a string terminator.

Then use:

Serial.print(t);

Hello, i already solved the problem taking account your advices.

My initial problem wasn't the one i posted at the beginning. It was a part of the problem. But i'm gonna explain it above.

I'm sending char character trough I2C between Arduino Nano & ESP8266EX (Nodemcu). Nodemcu works as master and Nano as slave. Nano is getting a float temperature value and Nodemcu ask for the value sending a command, once received the command i turn the value into a char array with dtostrf function and i send it with Wire.write(value) byte to byte. After, Nodemcu has to reconstruct the value saving each byte readed in a local array. The real problem was that garbage was being printed in data received.

As i said, taking account your advices i could fix the problem. Maybe is not the best solution but i'm gonna post the function which gets a string value from I2C without getting garbage.

char arreglo[5];

void getValue(byte slave_address, int Tsen, char* arreglo){
char* str = (char*)malloc(5sizeof(char));
Wire.beginTransmission(slave_address);
Wire.write (Tsen);
Wire.endTransmission();
delay(300);
Wire.requestFrom(slave_address, 5); // request 5 bytes from slave device #1
int i=0;
while(Wire.available())
{
str
=Wire.read();*
arreglo = str*;*
* i=i+1;*
* }*
* Serial.print("Transmited Value: ");*
* Serial.println(arreglo);*
* free(str);*
* }*

Please remember to use code tags when posting code.

I don't understand why you bother malloc-ind and then free-ing an intermediate buffer.