#include"stdlib.h"
#include"stdio.h"
struct stud_type
{
char name[20];
long num;
int age;
char sex;
}student[30];
int n=0;
main()
{
char ch;
int flag=1;
while(flag)
{
printf("\ntype'E'or'e'to enter new record,");
printf("type'L'or'l'to all list record:");
ch=getchar();
getchar();
switch(ch)
{
case'e':
case'E':new_record();break;
case'l':
case'L':listall();break;
default:flag=0;
}
}
}
new_record(void)
{
char numstr[20];
printf("\nrecord%d:\nenter name:",n+1);
gets(student[n].name);
printf("\nenter number:");
gets(numstr);
printf("\nenter age:");
gets(numstr);
printf("\nenter sex:");
student[n].sex=getchar();
getchar();
n++;
}
listall(void)
{
int i;
if (n<1)
printf("\nempty list. \n");
for(i=0;i{
printf("\nrecord number %d\n",i+1);
printf("name:%s\n,"student[i].name);
printf("num :%ld\n",student[i].num);
printf("age :%d\n",student[i].age);
printf("sex :%c\n",student[i].sex);
}
}
您刚才发送的消息:“#include"stdlib.h"
#include"stdio.h"
struct stud_type
{
char name[20];
long num;
int age;
char sex;
}student[30];
int n=0;
main()
{
char ch;
int flag=1;
while(flag)
{
printf("\ntype'E'or'e'to enter new record,");
printf("type'L'or'l'to all list record:");
ch=getchar();
getchar();
switch(ch)
{
case'e':
case'E':new_record();break;
case'l':
case'L':listall();break;
default:flag=0;
}
}
}
new_record(void)
{
char numstr[20];
printf("\nrecord%d:\nenter name:",n+1);
gets(student[n].name);
printf("\nenter number:");
gets(numstr);
printf("\nenter age:");
gets(numstr);
printf("\nenter sex:");
student[n].sex=getchar();
getchar();
n++;
}
listall(void)
{
int i;
if (n<1)
printf("\nempty list. \n");
for(i=0;i{
printf("\nrecord number %d\n",i+1);
printf("name:%s\n,"student[i].name);
printf("num :%ld\n",student[i].num);
printf("age :%d\n",student[i].age);
printf("sex :%c\n",student[i].sex);
--------------------next---------------------
阅读(1244) | 评论(0) | 转发(0) |