strcpy() 问题!
main(){
char s[] = "today", *p;
strcpy(p, s);
printf("%s\n", p);
}
为什么会错误呢????
2006-09-13 19:00
这样运行有错误吗?不可能呀
#include<stdio.h>
#include<string.h>
int main()
{
char s[] = "today", *p;
strcpy(p, s);
printf("%s\n", p);
return 0;
}

2006-09-13 19:32
2006-09-13 19:59
2006-09-13 20:18
#include "Stdio.h"
#include "string.h"
#include "stdlib.h"
#include "Conio.h"
int main()
{
char s[] = "today", *p;
p=(char *)malloc(sizeof(char)*(strlen(s)+1));
if(p==NULL)
exit(EXIT_FAILURE);
strcpy(p, s);
printf("%s\n", p);
free(p);
getch();
return 0;
}
没有为指针p分配空间.此时p是野指针。

2006-09-13 20:36

2006-09-14 08:04
2006-09-14 10:07
2006-09-19 19:11
*p指到哪里了啊??是不是没有赋值啊!!
2006-09-19 19:54
2006-09-20 12:27