#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>

typedef int element;
typedef struct temp{
        element n;
        char nm[10];
        element k;
        element e;
        element m;
}temp;
typedef struct ListNode{
        element num;
        char name;
        element kor;
        element eng;
        element mat;
        struct ListNode *link;
}ListNode;

typedef struct{
        ListNode *head;
        int length;
}LinkedListType;

void error(char *message)
{
        fprintf(stderr,"%s\n",message);
        exit(1);
}

int is_empty(LinkedListType *list)
{
        if(list->head==NULL)
                return 1;

        else
                return 0;
}

void insert(ListNode **phead,ListNode *p,ListNode *new_node)
{
        if(*phead==NULL)
        {
                new_node->link=NULL;
                *phead=new_node;
        }
        else if(p==NULL)
        {
                new_node->link=*phead;
        }
        else
        {
                new_node->link =p->link;
                p->link=new_node;
        }
}

ListNode *get_node_at(LinkedListType *list,int pos)
{
        int i;
        ListNode *temp_node =list->head;
        if(pos<0)
                return NULL;
        for(i=0;i<pos;i++)
                temp_node=temp_node->link;
        return temp_node;
}

void add(LinkedListType *list,int pos,element NUM, char *NAME,element KOR,element ENG,element MAT)
{
                        
        ListNode *p;

        if((pos>=0)&&(pos<=list->length)){
                ListNode*node=(ListNode *)malloc(sizeof(ListNode));
        
                node->num=NUM;
                node->name=*NAME;
        
                node->kor=KOR;
                node->eng=ENG;
                node->mat=MAT;
                p=get_node_at(list,pos-1);
                insert(&(list->head),p,node);
                list->length++;
        }
}

void remove_node(ListNode **phead,ListNode *p,ListNode *removed)
{
        if(p==NULL)
        {
                *phead=(*phead)->link;
        }
        else
                p->link=removed->link;
        free(removed);
}

void delete(LinkedListType *list,int pos)
{
        if(!is_empty(list)&&(pos>=0)&&(pos<list->length))
        {
                ListNode *p=get_node_at(list,pos-1);
                remove_node(&(list->head),p,(p!=NULL)?p->link:NULL);
                list->length--;
                
        }
}
void clear(LinkedListType *list)
{
        int i;
        for(i=0;i<list->length;i++)
                delete(list,i);
}
void init(LinkedListType *list)
{
        if(list==NULL)return;
        list->length =0;
        list->head =NULL;
}

void display(LinkedListType *list)
{
        int i;
        ListNode *node=list->head;
        for(i=0;i<list->length;i++)
        {
                printf("%d",node->num);
                printf("%s",node->name);
                node=node->link;
        }
}

int main()
{
        FILE *fp;
        int i,cnt=0;
        temp emp ;
        LinkedListType list1;
        init(&list1);
        
        fp=fopen("data.txt","r");
        
        if(fp==NULL)
        {
                printf("data를 읽어오지 못하였습니다");
                return 0;
        }

        while(!feof(fp))
        {
                fscanf(fp,"%d %s %d %d %d",&emp.n,&emp.nm,&emp.k,&emp.e,&emp.m);
                cnt++;
        }
        rewind(fp);

        

        for(i=0;i<cnt;i++)
        {
                fscanf(fp,"%d %s %d %d %d",&emp.n,emp.nm,&emp.k,&emp.e,&emp.m);
                add(&list1,i,emp.n,emp.nm,emp.k,emp.e,emp.m);                                                          /*이쪽 문자열부터 문제발생 ㅠㅠ
        
                        
        }
        
        return 0;
}

-------------------------------------------------------------------------------------------------------
코드를 짜서 확인해 봤는데 add함수 라는 곳에 문자열 입력받는곳부터 계속 문제가 발생하는데 이유좀 알고 싶어요 ㅠㅠ

물어보고싶어도 아싸여서 물어볼사람이 없음 ㅜㅜㅜ

입력해서 가져오는 파일내용은 대략 이렇스빈다

20074241 카하타 50 90 95
20074242 가나다 80 95 85
20074243 라마바 70 60 95
20074244 사아자 50 30 65