关于结构体的一点小问题

renbin5566 2010-05-10 12:00:19
# 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);
//getch();
//printf("input name:");
gets(stu[n].name);
//printf("\n");
//printf("input number:");
gets(numstr);
stu[n].num=atol(numstr);
//printf("\n");
//printf("input sex:");
stu[n].sex=getchar();
//printf("\n");
//printf(" input score:\n");
gets(numstr);
stu[n].scor=atof(numstr);
}
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=0;
char ch;
if(flag==0)
{
printf("please input you choice \n");
// printf("if you want iuput data please choice N or n,if you want to list data please output y orY:\n);
scanf("%c",&ch);
if(toupper(ch)=='N')
newdata();
else if(toupper(ch)=='Y')
list();
else
flag=1;
}
}
运行有点问题,不能正常运行
...全文
69 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
匚匚 2010-05-10
  • 打赏
  • 举报
回复
gets不安全,这里有个完整的学生学籍管理系统纯C代码,楼主可以去看一下。其它功能可自行扩充
http://blog.csdn.net/zhw952/archive/2010/05/02/5550803.aspx
田暗星 2010-05-10
  • 打赏
  • 举报
回复
帮顶一下吧 人这么少

69,368

社区成员

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

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