标题:求大神给这个程序建立文件保存数据!!!
只看楼主
recognized
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-7-8
结帖率:0
已结贴  问题点数:20 回复次数:3 
求大神给这个程序建立文件保存数据!!!
#include <time.h>
#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
#include<string.h>
#define NUM 200
void input();
void record();
void find();
void modify();
int now_no=0;
struct Client
{
    char name[20];
    int sex; //性别,0表示男,1表示女
    int age;
    char ID_card[20];
    int year;
    int month;
    int date;
    int Room_ID;
    int Tel;
    int Price;
    char Sign[10];
}Room[NUM];
int main()
{
    int as;
    do{
        start: printf("\n\t\t======================================================\n");
        printf("\n\t\t==================欢迎使用客房管理系统================\n");
        printf("\n\t\t                     1.登记入住  \n                       ");
        printf("\n\t\t                     2.统计客房    \n                     ");
        printf("\n\t\t                     3.查询宾客信息  \n                   ");
        printf("\n\t\t                     4.修改宾客信息    \n                 ");
        printf("\n\t\t                     5.退出              \n               ");
        printf("\n\t\t======================================================\n");
        printf("\n\t\t======================================================\n");
        printf("\t\t\t请输入数字进行选择:");
        fflush(stdin);
        scanf("%d",&as);
        switch(as){
        case 1:;input();break;
        case 2:;record();break;
        case 3:;find();break;
        case 4:;modify();break;
        case 5:;exit(0);
        default:;goto start;
        }
    }
    while(1);
}

void input()
{
    int i=0;
    char ch;
    do
    {
        printf("\t\t\t\t1.录入宾客信息\n\n");
        printf("输入第%d宾客的信息\n",i+1);
        printf("\n输入宾客姓名");
        fflush(stdin);
        gets(Room[i].name);
        printf("\n输入宾客性别:");
        fflush(stdin);
        scanf("%d",&Room[i].sex);
        printf("\n输入宾客的年龄:");
        fflush(stdin);
        scanf("%d",&Room[i].age);
        printf("\n输入宾客身份证号:");
        fflush(stdin);
        scanf("%s",&Room[i].ID_card);
        printf("\n输入宾客入住时间:");
        fflush(stdin);
        scanf("%d",&Room[i].year);
        scanf("%d",&Room[i].month);
        scanf("%d",&Room[i].date);
        fflush(stdin);
        printf("\n输入宾客房间号:");
        scanf("%d",&Room[i].Room_ID);
        fflush(stdin);
        printf("\n输入宾客房间电话:");
        scanf("%d",&Room[i].Tel);
        fflush(stdin);
        printf("\n输入宾客房间价格:");
        scanf("%d",&Room[i].Price);
        fflush(stdin);
        printf("\n输入该房间是否入住(yes/no):");
        gets(Room[i].Sign);
        fflush(stdin);
        printf("\n\n");
        i++;
        now_no=i;
        printf("是否继续输入?(Y/N)");
        fflush(stdin);
        ch=getch();
        system("cls");
    }
    while(ch!='n'&&ch!='N');
    system("cls");
}


void record()
{
    int i,y,m,d,s=0;
    static n=0;
    printf("\n客房入住总数:");
    fflush(stdin);
    for(i=1;i<=now_no;i++)
        n=n+1;
    printf("%d\n",n);
    printf("输入日期:\n");
    scanf("%d,%d,%d",&y,&m,&d);
    fflush(stdin);
    printf("该天客房入住数总数:");
    fflush(stdin);
    for(i=1;i<=now_no;i++)
        if(!((Room[i].year==y)&&(Room[i].month==m)&&(Room[i].date==d)))
            s=s+1;
        printf("%d\n",s);
        system("cls");
}

void find()
{
    int i;
    char str[200],as;
    do{
        printf("输入要查询的宾客姓名:");
        fflush(stdin);
        gets(str);
        for(i=0;i<now_no;i++)
            if(!strcmp(Room[i].name,str)){
                printf("姓名%s\n性别%d\n年龄%d\n宾客身份证号%s\n宾客入住时间%d,%d,%d\n宾客房间号%d\n宾客房间电话%d\n宾客房间价格%d\n该房间是否入住(yes/no)%s\n",Room[i].name,Room[i].sex,Room[i].age,Room[i].ID_card,Room[i].year,Room[i].month,Room[i].date,Room[i].Room_ID,Room[i].Tel,Room[i].Price,Room[i].Sign);
            }
            printf("\t\t按任意键返回主菜单.");
            fflush(stdin);
            as=getch();
    }
    while(!as);
    system("cls");
}


void modify()
{
    int i;
    char str[20],as;
    printf("输入要修改的宾客姓名:");
    fflush(stdin);
    gets(str);
    for(i=0;i<now_no;i++)
        if(!strcmp(Room[i].name,str)){
            system("cls");
            printf("\n\t\t输入新插入宾客信息\n");
            printf("\n输入宾客姓名:");
            fflush(stdin);
            scanf("%s",Room[i].name);
            printf("\n输入宾客性别:");
            fflush(stdin);
            scanf("%d",&Room[i].sex);
            printf("\n输入宾客的年龄:");
            fflush(stdin);
            scanf("%d",&Room[i].age);
            printf("\n输入宾客身份证号:"); fflush(stdin);
            scanf("%c",&Room[i].ID_card);
            printf("\n输入宾客入住时间:"); fflush(stdin);
            scanf("%d",&Room[i].year);
            scanf("%d",&Room[i].month);
            scanf("%d",&Room[i].date);
            fflush(stdin);
            printf("\n输入宾客房间号:");
            scanf("%d",&Room[i].Room_ID);
            fflush(stdin);
            printf("\n输入宾客房间电话:"); scanf("%d",&Room[i].Tel);
            fflush(stdin);
            printf("\n输入宾客房间价格:"); scanf("%d",&Room[i].Price);
            fflush(stdin);
            printf("\n输入该房间是否入住(yes/no)"); gets(Room[i].Sign);
            printf("\n\n");
            break;
        }
        system("cls");
}
搜索更多相关主题的帖子: include modify record start 
2015-07-08 21:25
recognized
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-7-8
得分:0 
求大神!!
2015-07-08 21:27
实际应用
Rank: 5Rank: 5
等 级:职业侠客
威 望:2
帖 子:89
专家分:341
注 册:2015-5-30
得分:10 
只写一个原型,容错处理自己加
void save()
{
    int i;
    FILE *fp;   
    fp = fopen("c:\customer.txt","w");
    fwite(Room, sizeof(struct Client), now_no,fp);
    fclose(fp);
 }



2015-07-08 22:06
rolimi
Rank: 4
等 级:业余侠客
威 望:1
帖 子:43
专家分:232
注 册:2015-6-10
得分:10 
windows上open时加上"b"标记

呆呆的逗比程序猿
2015-07-08 22:53



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




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

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