结构的小问题,往大侠诊断一下

renbin5566 2010-05-10 03:14:45
# include <stdio.h>
# include <stdlib.h>
# include "ctype.h"
# include "conio.h"
# define N 50
static 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);

printf("input number:");
scanf("%ld",&stu[n].num);

printf("input sex:");
scanf("%c",&stu[n].sex);

printf("input score:");
scanf("%f",&stu[n].scor);
}
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);
if(toupper(ch)=='N')
newdata();
else if(toupper(ch)=='Y')
list();
else
flag=0;
}while(flag==1);
}
怎么得不到我想要的结果啊
...全文
46 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
_JeffreyWu 2010-05-10
  • 打赏
  • 举报
回复
记得结帖
_JeffreyWu 2010-05-10
  • 打赏
  • 举报
回复
给你改了下,阿门,原谅我吧

# 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);
}
向立天 2010-05-10
  • 打赏
  • 举报
回复
你想要什么结果?

69,370

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧