69,382
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void stringtest(char **a)
{
*a = (char*)malloc(sizeof(char)*100);
**a = '1';
**(a+1) = '2';
printf("function:%s\n",*a);
}
//void func(char)
int main(void)
{
char * t;
stringtest(&t);
printf("main:%s\n",t);
return 0;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void stringtest(char **a)
{
*a = (char*)malloc(sizeof(char)*100); //把*a 理解为 主函数里面的t指针
*(*a+0) = '1';
*(*a + 1) = '2';
*(*a + 2) = 0;
printf("function:%s\n",*a);
/*
char *t = (char*)malloc(sizeof(char)*100);
*(t+0)='1';
*(t+1)='2';
*(t+2)=0; 字符串记得加个ASCII 的0结尾 一般写成 '\0'
*/
}
int main(void)
{
char * t;
stringtest(&t);
printf("main:%s\n",t);
return 0;
}