读书人

C程序段异常谁帮小弟我改改多谢

发布时间: 2012-09-14 23:00:49 作者: rapoo

C程序,段错误,哪位高手帮我改改,谢谢。

C/C++ code
错误出现在这一句:ST->elem = (ElemType*)malloc(sizeof(ElemType)); #include <stdio.h>#define ERROR -1#define SUCCEED 0//#define EQ(a,b)   (!strcmp((a),(b)))typedef int KeyType;typedef struct{    char stu_id[15];    char name[20];    char Chinese[5];    char math[5];    char English[5];}ElemType;typedef struct{    ElemType *elem;    int length;}SSTable;int Create(SSTable *ST, int n){    ST->elem = (ElemType*)malloc(sizeof(ElemType)); //错误点    if (NULL == ST->elem)    {        return ERROR;    }    else    {        return SUCCEED;    }    return 0;}int main(void){    SSTable *ST;    Create(ST,5);    //printf("%s",ST->elem->stu_id);    printf("HELLO\n");    return 0;}


[解决办法]
在main函数中你没有给 SSTable型的指针分配内存就进行访问。

读书人网 >C语言

热点推荐