此程序有什么问题???

来源:百度知道 编辑:UC知道 时间:2024/06/13 23:04:46
#define NULL 0
#include "string.h"

unsigned char* main()

{

unsigned char i =0;

char *p=NULL;

int a =1000;

for (i=0;i<a;i++)

{

strcpy(p,"hello");

}

return &i;

}

p地址为NULL,如何strcpy
必须要给p分配一段内存,才能拷贝
p=(char*)malloc(sizeof(char)*6);

返回值是个局部变量,返回时候已经失效。

另为什么要用main函数呢?

把你定义的main()函数的地址赋给P,这样就可以了。