중간에 주석으로 말 써놨음
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student {
int id;
char name[20];
int score[4];
struct student *next;
};
int main()
{
int count = 0, id,sc[4];
char name[20],line[200];
struct student *p, *head = NULL, *cur=NULL;
printf("학번과 이름을 입력하세요\n");
fgets(line, 200, stdin);
while (fgets(line, 200, stdin) != NULL) {
sscanf(line, "%d %s %d %d %d %d", &id, name,
&sc[0],&sc[1],&sc[2],&sc[3]);
p = (struct student *) malloc(sizeof(struct student));
if( head=NULL)
head = p;
else
// 여기쯤에 뭔가 넣어야 하는데
// cur->next = p;
// cur=p;
if (p == NULL) {
perror("malloc");
exit(1);
}
p->id = id;
strcpy(p->name, name);
p->next = head;
for(int i=0; i< 4; i++)
p->score[i]=sc[i];
head = p;
}
printf("\n* 학생 정보*\n");
p = head;
while (p != NULL) {
count++;
printf("학번: %d 이름: %s : ", p->id, p->name);
for(int i=0; i< 4; i++)
printf("%6d", p->score[i]);
printf("\n");
p = p->next;
}
printf("총 %d 명입니다.\n", count);
exit(0);
}
이거 뭐 어케 넣어야함
링크드 리스트에 읽어들인 순서대로 저장하는 코드 짜래
왜 이걸 못풀겠지 ㅅㅂ
count는 무슨 카운트고 id는 무슨 id고 sc는뭐고 name은 누구이름이고 line은 무슨 line이고 p는 뭐야
아 외부 텍스트 파일에서 입력 받는거임;;
c안본지 좀 되긴했는데.. cur은 NULL로 초기화 되는데 cur->next이 아니지않음?