C语言中级教程+再谈指针.ppt

问题表(2) Q3:这段代码有问题吗? char *p = (char *)malloc(100); strcpy( p, “hello” ); free(p); … if (p != NULL) { strcpy(p, “world”); } 问题表(3) Q4:这段代码有问题吗? #include stdio.h #include string.h #includemalloc.h #define SIZE 4 void main() { int i,j; char str[100]; char *tstr[SIZE]; //创建指针数组 char *tp=NULL; printf(请输入字符串,以回车间隔!\n); for(i=0;iSIZE;i++) { scanf(%s,str); tstr[i]=(char *)malloc(strlen(str));//指针必须申请空间。strcpy(tstr[i],str); } printf(\n); for(i=0;iSIZE-1;i++) for(j=i;jSIZE;j++) if(strcmp(tstr[i],tstr[j])0) { tp=tstr[i]; tstr[i]

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档