I have a *char pointer and a char array. How can I put the value of the pointer in the char array? I've tried
uint8_t i;
char a[10];
char *b = "abcdefghi";
for(i = 0; i < 9; i++)
{
a[i] = b[i];
}
printf("%s", a);
But this doesn't work.
The size of a is 10, so is the length of b(including the null terminator). Change
for(i = 0; i < 9; i++)
to
for(i = 0; i < 10; i++)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With