王道oj/problem15(用c++的引用精简代码)


网址:http://oj.lgwenda.com/problem/15

思路:子函数的形参是指针的时候格式为 int*&p,且原函数实参为p

          主函数使用fgets(字符串的指针,最大容量,stdin标准输入)

代码:

#include
#include

void zcc(char *&p)
{
p = (char*)malloc(100);
fgets(p, 100, stdin);
}

int main()
{
char* p;
zcc(p);
printf("%s\n", p);
free(p);
p = NULL;
return 0;
}

相关