#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char a;
char *str=&a;
str=(char*)malloc(strlen("hello")+1); //注意:如果不加此条语句则str指向的空间只有一个字符所占的空间, //strcpy 后会产生溢出,提示该内存不能为read.
strcpy(str,"hello");
printf("%s\n",str);
free(str);
return 0;
}
#include <string.h>
#include <stdlib.h>
int main()
{
char a;
char *str=&a;
str=(char*)malloc(strlen("hello")+1); //注意:如果不加此条语句则str指向的空间只有一个字符所占的空间, //strcpy 后会产生溢出,提示该内存不能为read.
strcpy(str,"hello");
printf("%s\n",str);
free(str);
return 0;
}