Copy byte array to another array.

Hi there...
I am looking for the easiest way to copy an existing byte array value, that I successfully print on the serial monitor, to another array for later use.
I am printing the right values using:

byte dht11_dat[5];
Serial.print(dht11_dat[2], DEC);
	Serial.print(".");
	Serial.print(dht11_dat[3], DEC);

I want to capture (save) in another array the results.I cannot use atoi or strncpy commands.
Please help...
Thanks in advance!

The best way i have found to compare is to set up an array with the values u want to match with then when u bring ur serial data in set it up in a if statement and compare it there look at my last post with code on fingerprint scanner with uart communication post the way i set it up should help you out

Use a for loop or strcpy if it's null terminated.

Arrch:
Use a for loop or strcpy if it's null terminated.

I am having errors with the strncpy command....

char temp1[5];
byte dht11_dat[5];
Serial.print(dht11_dat[2], DEC); // I am getting this correctly
	Serial.print(".");
	Serial.print(dht11_dat[3], DEC); // I am getting this correctly

strncpy (temp1,&dht11_dat[0],1)  // cannot compile error in converting byte to char
Serial.print(temp1);

Please let me know how to copy as an integer or string the values... I am using the DHT11 sensor and I am trying to build a sketch that works without delay.
I need the variables so that I can use them every time I want.

Can someone also tell me how can I declare an array that is used in a function for public use?

nathanas:
&dht11_dat[0]

The bolded is redundant.

To get it to compile, you just need to typecast it to a char pointer

Can you please give me the code line that makes that happen? I don't know any of what you say... :frowning:

nathanas:
Can you please give me the code line that makes that happen? I don't know any of what you say... :frowning:

strncpy expects a pointer to a character that is assumed to be in an array. Since you have dh11_dat as a pointer to a byte (that is part of an array), you need to type cast it into a char pointer when you passing it into strncpy.
So from &dht11_dat[0] you remove the redundancy to make it dht11_dat and then type cast it into a char pointer instead of byte pointer: (char*) dht11_dat

strcpy() copies a C string (byte or char array) and puts a terminating zero at the end.
strncpy() copies without putting a terminating zero at the end.

strncpy() lets you copy into an existing C string, to replace some characters.
strcpy() would mess that up.

You would do fine to use a while-loop to make your array copy. Then you would know how it works.

true that i just learned all that this week the really hard way only to find out it was my preset array that was the issue lol

I made it by saaving to another array...

Now I need a byte stored in a specific place in an array to be converted to integer.... But atoi doesn't work.

How can I convert to integer the below?

byte temp1[5];
int temp2=0;

temp2=atoi(temp1[0],1);

Now I need a byte stored in a specific place in an array to be converted to integer.

What, exactly is in this array? Are there characters stored in the array? If so, and the character represents a numeric digit, simply subtract '0' from the value to get the digit ('8' - '0' = 8).

If not, then the value is already a (less than) int-sized value, so just store it in an int.

A byte is a number. An integer is a number. atoi() converts a string representation of a number into a number.

Just use

temp2 = temp1[0];

and temp2 will then contain the value that is stored in slice 1 of temp1. If temp1[0] contains 53, then temp2 will contain 53.

Thanks!

I figured that out at the time you posted...
It was pretty simple, but had beeen programming for 8 hours last night.
As soon as I woke up it took me about 20 minutes to find out my problem. And last night I'd been struggling for over 2 hours!
Programming can mess your brain up! :fearful: