关于结构体的一点小问题
# 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;
}
}
运行有点问题,不能正常运行