system
1
Hi,
as memory is critical for me I want to use limited char arrays instead of Strings, but how do I pass on such a char array?
That is what I am trying to do:
char arrTest1[10];
void assign(char arrTest2[10])
{
arrTest1 = arrTest2;
}
void loop()
{
assign("Name");
// arrTest1 should now be "Name"
}
Is there a way to do it or do I have to use Strings instead?
Kevin
char arrTest1[10];
void assign(char* arr)
{
strcpy(arr, "Name");
}
void loop()
{
assign(arrTest1);
// arrTest1 should now be "Name"
}
system
3
Thanks, that is one step in the right direction, but I need the assign function the other way around. Giving it the "Name".
I tried to adapt your code - this should do:
char arrTest1[10];
void assign(String Test2)
{
char chTest[10];
Test2.toCharArray(chTest, 10);
strcpy(arrTest1, chTest);
}
void setup()
{
}
void loop()
{
assign("Name");
// arrTest1 should now be "Name"
}
Thanks,
Kevin
system
4
char arrTest1[10];
void assign(char *arrTest2)
{
strcpy(arrTest1,arrTest2);
}
void loop()
{
assign("Name");
// arrTest1 should now be "Name"
}
Or, you can pass both:
char arrTest1[10];
void assign(char *dest,char *arrTest2)
{
strcpy(dest,arrTest2);
}
void loop()
{
assign(arrTest1, "Name");
// arrTest1 should now be "Name"
}
Or you can simplify it and forget the function entirely:
strcpy(arTest1,"Hello");