링크드리스트 및 파일입출력에 대한 질문입니다.
참
질문 제목 : 링크드리스트 및 파일입출력에 대한 질문입니다.제가 학생 총점 및 평균 랭킹 구하는 프로그램을 짜려고 합니다. 링크드리스트 및 파일입출력 그리고 strtok함수를 이용해서 짜야 하는데 아래와 같이 제가 코딩을하였는데.program에선 error가 안나는데 core dump가 뜨네요. 아마도링크드리스트를 잘못사용한것 같은데요. 어디가 잘못됬는지좀 알려주세요.ㅠㅠ 2시간째 보고 있는데 답이 안나오네요. 아래 프로그램은 각 변수를 넣는데까지만 코딩한 것입니다.질문 내용 :
file 내용
kor eng mat sci soc mug
lee 100 92 97 99 91 90
kim 81 72 63 93 82 93
park 9 83 92 71 39 42
choi 10 39 82 73 92 11
shin 84 32 44 8 93 5
seo 93 99 100 92 93 99
bang 11 10 92 99 100 93
ko 100 100 100 98 99 91
oh 93 72 92 74 63 53
song 19 49 99 100 100 92
#include stdio.h
#include stdlib.h
#include strings.h
#define max_len 10
typedef struct student_info{
char name[100];
float kor,eng,mat,sci,soc,mug,tot,ave;
int rank;
struct student_info *next;
}stu;
void add(stu **head,stu stu_info)
{
stu *add =(stu *)malloc(sizeof(stu));
stu *roof = *head;
strcpy(add-name, stu_info.name);
add-kor = stu_info.kor;
add-eng = stu_info.eng;
add-mat = stu_info.mat;
add-sci = stu_info.sci;
add-soc = stu_info.soc;
add-mug = stu_info.mug;
add-next = null;
while(roof-next != null)
roof= roof-next;
roof-next = add;
}
void print(stu **head)
{
stu *roof=(*head)-next;
while(roof != null)
{
printf(%s %f %f %f %f %f %f\n,roof-name,roof-kor,roof-eng,roof-mat,roof-sci,roof-soc,roof-mug);
roof=roof-next;
}
printf(\n);
}
int main()
{
stu stu_info;
char str[max_len];
char buf[256];
char *delimiter = ;
int i=0,j=0,sub_cnt=0;
int count =0;
int leng;
char tmp,*token;
float class_tot = 0;
float class_ave = 0;
file *fp;
fp = fopen(score.txt,rt);
leng = length_file(fp);
if (fp == null){
printf( error check youre socre file );
}
stu *head = (stu*)malloc(sizeof(stu));
head-next = null;
fseek(fp,+43,seek_set);
while /while(1)
{
if(fgets(buf,256,fp)==null) break;
token = strtok(buf,delimiter);
strcpy(stu_info.name,token);
token = strtok(null,delimiter);
stu_info.kor = atof(token);
token = strtok(null,delimiter);
stu_info.eng = atof(token);
token = strtok(null,delimiter);
stu_info.mat = atof(token);
token = strtok(null,delimiter);
stu_info.sci = atof(token);
token = strtok(null,delimiter);
stu_info.soc = atof(token);
token = strtok(null,delimiter);
stu_info.mug = atof(token);
add(&head,stu_info);
}
print(&head);
fclose(fp);
return 0;
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |
2691483 | 파일 오픈시 에러 질문드립니다. (2) | 호습다 | 2025-04-14 |
2691450 | [visual c++ 툴]기초 질문 (3) | 해긴 | 2025-04-13 |