생활
프로그래밍 중 자료구조에 관하여 질문드립니다.
-main함수
#include <stdio.h>
#include "Com_In_head.h"
int main(void)
{
List plist;
ListInit(&plist);
Linsert(&plist, 154998, "kim");
Linsert(&plist, 141850, "jin");
Linsert(&plist, 176236, "park");
Linsert(&plist, 187649, "harry");
return 0;
}
-헤더파일
#ifndef __Com_In_Head__
#define __Com_In_head__
typedef struct ComH
{
int Hnum;
char *Hname;
}ComH;
typedef struct _node
{
ComH *data;
struct _node * next;
}Node;
typedef struct _Cll
{
Node *tail;
Node *cur;
Node *before;
int numOfData;
}List;
void ListInit(List *plist);
void Linsert(List *plist, int Hnum,char *Hname);
/*int Lfirst(List *plist, int *pdata);
int Lnext(List *plist, int *pdata);
int Lremove(List *plist);
int Lcount(List *plist);*/
#endif
-헤더파일에 선언된 함수코드
#include <stdio.h>
#include "Com_In_Head.h"
void ListInit(List *plist)
{
plist->tail = NULL;
plist->cur = NULL;
plist->before = NULL;
plist->numOfData = 0;
}
void Linsert(List *plist, int HNum, char *HName)
{
Node *newnode = (Node*)malloc(sizeof(Node));
newnode->data->Hnum = HNum;
newnode->data->Hname = HName;
if (plist->tail == NULL)
{
plist->tail = newnode;
newnode->next = newnode;
}
else
{
plist->tail->next = newnode;
newnode->next = plist->tail->next;
plist->tail = newnode;
}
plist->numOfData++;
}
보기가 명확하지는 않은데요!
Linsert함수에서
newnode->data->Hnum = HNum; newnode->data->Hname = HName;
이 코드가 쓰기 엑세스 위반이라고 뜨는데 이유가 뭔가요?
아직 답변이 없어요.