请问这个程序错在哪里?#include#include#includeint main(){char *a;char *b;b=(char *)malloc(5*sizeof(char));b[2]='m';b[3]='n';b[4]='\0';a=(char *)malloc(9*sizeof(char));strcpy(a,b);printf("%s\n",a);}

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/14 21:11:01

请问这个程序错在哪里?#include#include#includeint main(){char *a;char *b;b=(char *)malloc(5*sizeof(char));b[2]='m';b[3]='n';b[4]='\0';a=(char *)malloc(9*sizeof(char));strcpy(a,b);printf("%s\n",a);}
请问这个程序错在哪里?
#include
#include
#include
int main()
{char *a;
char *b;
b=(char *)malloc(5*sizeof(char));
b[2]='m';b[3]='n';b[4]='\0';
a=(char *)malloc(9*sizeof(char));
strcpy(a,b);
printf("%s\n",a);
}

请问这个程序错在哪里?#include#include#includeint main(){char *a;char *b;b=(char *)malloc(5*sizeof(char));b[2]='m';b[3]='n';b[4]='\0';a=(char *)malloc(9*sizeof(char));strcpy(a,b);printf("%s\n",a);}
strcpy(a,b);
改为strcpy(a,b+2);
应为前面两位没赋值