Home > Back-end >  Pointer to function in the returned string problem for help bosses!!!!!!
Pointer to function in the returned string problem for help bosses!!!!!!

Time:01-03

Test1:

# include


Void s (char * * t)
{
* t="CSDN";
}
The main ()
{
Char * a;
S (& amp; A);
Printf (" % s ", a);

}

Test2:

# include


Void s (char * * t)
{
Char \ [10]="CSDN";
//* t=temp;
//strcpy (* t, temp);
//t=& amp; Temp.
}
The main ()
{
Char * a;
S (& amp; A);
Printf (" % s ", a);

}




For help, I want to put the function of the string through the pointer back to now, direct assignment test1, can return to normal, test2 store variables in the string can't back, no matter use * t=temp; Or strcpy (* t, temp); Or t=& amp; Temp. Can't, for help, thank you

CodePudding user response:

The
refer to the original poster JayChou_ChengDu response:
test1:

# include


Void s (char * * t)
{
* t="CSDN";
}
The main ()
{
Char * a;
S (& amp; A);
Printf (" % s ", a);

}

Test2:

# include


Void s (char * * t)
{
Char \ [10]="CSDN";
//* t=temp;
//strcpy (* t, temp);
//t=& amp; Temp.
}
The main ()
{
Char * a;
S (& amp; A);
Printf (" % s ", a);

}




For help, I want to put the function of the string through the pointer back to now, direct assignment test1, can return to normal, test2 store variables in the string can't back, no matter use * t=temp; Or strcpy (* t, temp); Or t=& amp; Temp. Can't, ask for help, thank you

Pointer is not allocate memory

CodePudding user response:

Char \ [10]="CSDN" this character array is allocated on the stack, a subroutine exit is destroyed, preach not go out, of course, should use malloc allocation of memory, and then back to the pointer
  • Related