#include <stdio.h>
#include <stdlib.h>
struct student
{
char name[10];
int result; //期末平均成績
int review; //班級測評成績
char bo; //是否西部學生
int papnum; //論文數
struct student *next;
} Mystu;
int n;
struct student *input()
{
int i;
struct student *head=NULL,*p=NULL,*q=NULL;
for(i=0;i<n;i++)
{
q=p;//保存前一個元素的地址 將p的地址賦給q
p=(struct student *)malloc(sizeof(struct student));
printf("第%d個學生的資訊(包括:姓名 期末成績 班級測評 是否西部學生 論文數)\n",i+1);
scanf("%s%d%d%d%d",&p->name,&p->result,&p->review,&p->bo,&p->papnum);
p->next=NULL;
if(head==NULL)
head=p;
else
q->next=p;
}
return head;
}
void output(struct student *head)
{
struct student *p=NULL;
p=head;
while(p!=NULL)
{
printf("%s%d%d%s%d\n",p->name,p->result,p->review,p->bo,p->papnum);
printf("%s\n",p->name);
printf("%d\n",p->result);
printf("%d\n",p->review);
printf("%s\n",p->bo);
printf("%d\n",p->papnum);
p=p->next;
}
}
int main()
{
struct student *head=NULL;
printf("please input student number(n):\n");
scanf("%d",&n);
head=input();
printf("main:%p \n", head);
output(head);
return 0;
}
uj5u.com熱心網友回復:
你結構體是這樣宣告這個的char bo; //是否西部學生,而你輸入卻是這樣輸入的
scanf("%s%d%d%d%d",&p->name,&p->result,&p->review,&p->bo,&p->papnum);可是你列印的時候居然是這樣列印的printf("%s%d%d%s%d\n",p->name,p->result,p->review,p->bo,p->papnum);[code=c]printf("%s\n",p->bo);你到底是想這個bo是int ? char ? string ?我就不知道了!
uj5u.com熱心網友回復:
scanf("%s%d%d%d%d",&p->name,&p->result,&p->review,&p->bo,&p->papnum);輸入格式與其資料型別不匹配,還有name既然是字串,那輸入時不用加上&,先改了這個再說吧
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/113002.html
標籤:基礎類
下一篇:歡迎C++同學前來幫忙!
