标题:交通处罚单管理程序
只看楼主
wly2014
Rank: 2
等 级:论坛游民
帖 子:29
专家分:19
注 册:2014-2-25
结帖率:88.89%
已结贴  问题点数:20 回复次数:3 
交通处罚单管理程序
#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]
搜索更多相关主题的帖子: records include 管理程序 结构体 
2014-04-16 23:24
蚕头燕尾
Rank: 10Rank: 10Rank: 10
来 自:Gryffindo
等 级:贵宾
威 望:12
帖 子:734
专家分:1546
注 册:2013-3-24
得分:10 
“输入一组信息”--->你这里输入的时候格式是怎样的?(我是说你运行程序的时候,输入的数据格式)


学习编程,为的是表达自己的思想,而不是被别人的思想所禁锢。要先明白自己想干嘛,而不要先问别人让你干嘛。               

                                                                                                                    Black Cat      Hello Tomorrow~
2014-04-17 01:02
wly2014
Rank: 2
等 级:论坛游民
帖 子:29
专家分:19
注 册:2014-2-25
得分:0 
我是先输入1,然后回车,在输入Wang空格 123456再回车的
2014-04-17 11:16
Andrew_Lee
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:185
专家分:626
注 册:2014-3-21
得分:10 
Input函数中的scanf("%s%d ",records[m].driver,&records[m].car);将%d后面的空格去掉,变为scanf("%s%d",records[m].driver,&records[m].car);通常情况下,int 最大表示的65535,你的123456最好还是用long来表示。


[ 本帖最后由 Andrew_Lee 于 2014-4-17 14:29 编辑 ]
2014-04-17 14:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-430205-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023696 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved