链接列表的代码应该是在排列数据之后至少打印一些内容,但即使编译和运行时没有错误也不打印任何内容。
可能是什么问题?
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
typedef struct data {
char name[16];
int subj1, subj2, subj3, total_score;
} data;
data stud[10];
typedef struct LINK {
data score;
struct LINK *next;
} LINK;
LINK create_list(data s[], int length);
void print_list(LINK *LINK);
int main(void) {
int i;
int length = 10;
FILE *fp = fopen("student.txt", "r");
printf("***Data collected***\n");
printf("Name (1) (2) (3)\n");
LINK create_list(data stud[10], int length);
void print_list(LINK create_list);
for (i=0; i<length; ++i) {
while (fgets(stud[i].name, 16, fp) != 0) {
fscanf(fp, " %d %d %d ", &stud[i].subj1, &stud[i].subj2, &stud[i].subj3);
stud[i].total_score = stud[i].subj1 + stud[i].subj2 + stud[i].subj3;
break;
}
}
fclose(fp);
return 0;
}
LINK create_list(data s[], int length) {
LINK *head, *temp;
head = NULL;
for (int i = 0; i < length; i++) {
temp = head;
head = (LINK*)malloc(sizeof(data));
head->score = s[i];
head->next = temp;
}
return *head;
}
void print_list(LINK *p) {
printf("\n%s\n", p->score.name);
}
我希望以下列方式打印:
Eom Ji Chuk 97 85 80
Kim Wang Jjang 70 47 55
Oh Se Yong 50 65 47
Bus Card Chung 12 75 100
Haek Honey Jam 80 83 81
Kong Jeong Cheo 100 100 100
Dap Jeong you 70 70 70
Lip Took Twi 100 100 99
Lim Woo Jin 24 21 20
Bur ger King 43 99 79
我应该使用链接列表创建列表并打印列表,但我甚至无法打印名称。
似乎 create_list 功能和 print_list 功能无效。 请告诉我哪个部分我做错了?