Chinaunix
标题:
大虾,帮帮忙:)我的程序core掉了
[打印本页]
作者:
liuyanghr
时间:
2003-02-27 11:25
标题:
大虾,帮帮忙:)我的程序core掉了
#include <stdio.h>;
#include <string.h>;
#define LEN 4
typedef struct tagSTR
{
char szStr0[LEN * 4];
}STR;
typedef STR * PSTR;
void main()
{
char szStr1[LEN];
PSTR pstr;
memset(pstr->;szStr0, 0, sizeof(pstr->;szStr0));
memset(szStr1, 0, LEN);
memcpy(szStr1, "123", 3);
strcpy(pstr->;szStr0, szStr1);
printf("szStr0 = %s\n", pstr->;szStr0);
}
大虾,帮帮忙:)
我的程序core掉了:(
怎么会这样?:(
作者:
unicorns
时间:
2003-02-27 11:32
标题:
大虾,帮帮忙:)我的程序core掉了
没有给pstr分配空间
pstr = (PSTR)malloc(sizeof(STR));
作者:
liuyanghr
时间:
2003-02-27 11:45
标题:
大虾,帮帮忙:)我的程序core掉了
谢谢,现在能用了
:)
作者:
horse
时间:
2003-02-27 16:40
标题:
大虾,帮帮忙:)我的程序core掉了
很多时候需要申请内存空间,特别是对内存空间操作的函数,如:memset,memcpy和其他mem开头的函数.当然用完要free.
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2