I've been struggling to fix this since morning. The value 'pd' pm
doesn't change outside the function. Could someone tell me what the mistake is?
void foo(u8 *pm, u8 *pd)
{
pm = "IWR ";
memcpy(pd, pm, sizeof(pm));
printf("in foo pm = %s, pd = %s \n", pm, pd);
}
int main()
{
u8 pm[5] = "0";
u8 pd[5] = "IWO ";
printf("pm = %s, pd = %s \n", pm, pd);
foo(pm, pd);
printf("after pm = %s, pd = %s \n", pm, pd);
}
My final output after call to foo is pm
= (null) and pd
= "IWO ". I thought that 'pm' also would change value.
(Here is the code on ideone, but in that case pm
prints as 0
, not (null)
. Why is this? )
pm = 0, pd = IWO
in foo pm = IWR , pd = IWR
after pm = 0, pd = IWR