单链表究竟该如何调用呢?不知哪里错了?
为什么输入了5个数却无法输出呢?程序代码:
#include <stdio.h> #include<stdlib.h> typedef struct student { int score; struct student *next; }Link; //函数声明// Link *creat(int); void print(Link *head,int n); //构造一个单链表// Link *creat(int n) { Link *head,*node,*end; head=(Link*)malloc(sizeof(Link)); end=head; int i; for (i=0;i<n;i++) { node=(Link*)malloc(sizeof(Link)); scanf("%d",&node->score); end->next=node; end=node; } end->next=NULL; return head; } //依次输出每个数// void print(Link *head,int n) { int i=0; while(i<n) {head=head->next; printf("%d",head->score); i++; } //主函数调用,输入5个int数// main() { Link *p; p=creat(5); print(p,5); }