69,370
社区成员
发帖
与我相关
我的任务
分享
# include <stdio.h>
# include <stdlib.h>
# include <ctype.h>
# include <conio.h>
# define N 50
static int n=0;
struct stuinfo{
char name[20];
long num;
char sex;
float scor;
}stu[N];
void newdata()//建立一个学生信息
{
char numstr[15];
printf("please input the %d strdents's datas(name,num,sex,scor)\n",n+1);
printf("input name:");
scanf("%s",stu[n].name);
getchar();
printf("input number:");
scanf("%ld",&stu[n].num);
getchar();
printf("input sex:");
scanf("%c",&stu[n].sex);
getchar();
printf("input score:");
scanf("%f",&stu[n].scor);
getchar();
n++; // 每次newdata完了,n++
}
void output(struct stuinfo *s,int k)//输出
{
printf("%-12s\t-8ld\t %c\t&6.2f\n",s->name,s->num,s->sex,s->scor);
}
void list()//列出学生信息
{
int i;
if(n<=0)
printf("error,this is emoty list:");
for(i=0;i<n;i++){
printf("the %d student data is:",n+1);
output(stu,n);
}
}
void main()
{
int flag=1;
char ch;
do //如果是n就输入,y就输出其他的就结束
{
printf("please input you choice \n");
printf("nto shuru\n");
scanf("%c",&ch);
getchar();
if(toupper(ch)=='N')
newdata();
else if(toupper(ch)=='Y')
list();
else
flag=0;
}while(flag==1);
}