交通处罚单管理程序
#include <stdio.h>#include <stdlib.h>
#include <ctype.h>
struct Records{
char driver[20];
int car;
};
void Display(struct Records records[],int n);
int Input(struct Recoeds records[],int n);
int menu_select();
main(){
int m=0;
struct Records records [40]; //结构体数组
for (;;){
switch (menu_select()){
case 1:
printf("Input records\n");
m=Input(records,m); // A
break; // B
case 2:
printf("Display all records\n");
Display(records,m);
break;
case 3:
printf("Delet a record\n");
system("pause");
break;
case 4:
printf("Sort\n");
system("pause");
break;
case 5:
printf("Insert arecords\n");
system("pause");
break;
case 6:
printf("Query\n");
system("pause");
break;
case 7:
printf("Add records from a test file\n");
system("pause");
break;
case 8:
printf("Write to a Text File\n");
system("pause");
break;
case 0:
printf("Goodbye!\n");
system("pause");
exit(0);
}
}
}
int menu_select(){
char c;
do{
system("cls");
printf("1.Input records\n");
printf("2.Display all records\n");
printf("3.Delet a record\n");
printf("4.Sort\n");
printf("5.Insert arecords\n");
printf("6.Query\n");
printf("7.Add records from a test file\n");
printf("8.Write to a Text File\n");
printf("0.Quit\n");
printf("Input 0-8:");
c=getchar();
}while(c<'0'||c>'8');
return(c-'0');
}
int Input(struct Records records[],int m){
scanf("%s%d ",records[m].driver,&records[m].car);
return m++;
}
void Display(struct Records records[] ,int m){
int i;
for(i=0;i<m;i++)
printf("\n%s\t%d\n",records[i].driver,records[i].car);
}
说明:本来我是想先调用Input函数,然后在输入一组信息,按回车后,理论上应该return,然后到B处,break;之后在for循环。但现在他却还在等待我输入?怎么回事??[local]1[/local]