#include "stdio.h"#include<malloc.h>#include<string.h>#define LEN sizeof(struct student)struct student{int num;int score;struct student*next;};struct student*create(){? ? char ch;? ? struct student *head;? ? struct student*p1,*p2;? ? int a=0;? ? printf("是否輸入新數(shù)據(jù):(y/n)");? ? while(toupper(ch=getche())=='Y');//這個(gè)不是要輸入輸出y多次,輸入輸出多個(gè)num,score,直到ch不等于y,但是為什么只有輸入輸出一次? ? {? ? p1=(struct student*)malloc(LEN);? ? printf("\n請輸入:");? ? scanf("%d%d",&p1->num,&p1->score);? ? printf("是否輸入新數(shù)據(jù):(y/n)");? ? a++;? ? if(a==1) head=p1;? ? else p2->next=p1;? ? p2=p1;? ? p1->next=NULL;? ? }? ? return(head);}void print(struct student *head){struct student *p;p=head;while(p!=NULL){printf("\n學(xué)號:%d,成績:%d",p->num,p->score);p=p->next;}}void main( ){struct student *stu;stu=create();print(stu);}
動態(tài)鏈表,怎么才能改成像課本上的可以輸入輸出多次,
溯源1
2017-01-16 12:06:56