didashao didashao
关注数: 26 粉丝数: 14 发帖数: 357 关注贴吧数: 24
刚做的列车时刻表程序,觉得蛮垃圾的,请高手进来改改 这是个列车时刻表程序.要求按地点.车次查询和信息更新,我只做了前面两个,更新不会,高手试试改进改进~~#include struct train{ char first[20]; char last[20]; /**/ char num[20];}t[100];message();form();search();byfirstplace();bylastplace();bytrainnumber();edit();load();FILE *fp;int k;char q,p[20];int i;char order;main() {load();message(); }message() { clrscr(); printf("\n========Menu========\n1.Form\n2.Search\n"); printf("3.Edit\n4.Exit\n==========\nPlease Choose One: "); scanf("%c",&order); switch(order) { case '1':form();fclose(fp);break; case '2': search();fclose(fp);break; case '3': edit();fclose(fp);break; case '4': fclose(fp);exit(); default: message(); };}form() {printf("\n======Table======\nFirstplace\t Lastplace\tTrainnumber\n"); i=0; do{ printf("%s\t %s\t %s\t\n",t[i].first,t[i].last,t[i].num);i++;} while(strlen(t[i].first)>1); printf("\n======================\nAny key to the menu.\n"); getch(); message(); }search() {clrscr(); printf("\n=====Menu=====\n1.byfirstplace.\n2.bylastplace."); printf("\n3.bytrainnumber\n4.Exit\n======\nPlease Choose One: "); scanf("%c",&order); switch(order) { case '1': byfirstplace();break; case '2': bylastplace();break; case '3':bytrainnumber();break; case '4': message();break; default: search(); }; }byfirstplace() { clrscr(); printf("\n======Menu======\n1.Search\n2.Quit\n======\nPlease choose one:"); scanf("%c",&q); switch(q) { case'1':{i=0; k=0; printf("\n=====Search======\nplease enter the first place:"); scanf("%s",p); printf("===========Table===============\n"); do{if(strcmp(p,t[i].first)==0) {printf("\nfirstplace: %s",t[i].first); printf("\tendplace: %s\tnumber: %s",t[i].last,t[i].num); k=1;} i++;}while(strlen(t[i].first)>1); printf("\n============================\n"); getch(); if(k!=1) {printf("\nno train found!\nAny key to the menu.\n"); getch(); }; byfirstplace();}; case'2': search(); default: byfirstplace();}; }bylastplace(){ clrscr(); printf("\n=========Menu======\n1.Search\n2.Quit"); printf("\n=========\nPlease choose one:"); scanf("%c",&q); switch(q) { case'1':{i=0; k=0; printf("\n========Search=================\n"); printf("please enter the first place:"); scanf("%s",p); printf("===========Table===============\n"); do{if(strcmp(p,t[i].last)==0) {printf("firstplace:%s\tendplace:%s\tnumber:%s\n",t[i].first,t[i].last,t[i].num); k=1;}i++;}while(strlen(t[i].first)>1);printf("======================\n"); getch(); if(k!=1){printf("\nno train found!\nAny key to the menu.\n"); getch();}; bylastplace();}; case'2': search(); default: bylastplace();}; }bytrainnumber()
1 下一页