标题:我的这个停车场管理系统虽然做好了。但是文件这方面还是不懂。帮忙看一下。 ...
取消只看楼主
liu_鹏
Rank: 2
等 级:论坛游民
帖 子:33
专家分:75
注 册:2013-4-16
结帖率:60%
已结贴  问题点数:10 回复次数:1 
我的这个停车场管理系统虽然做好了。但是文件这方面还是不懂。帮忙看一下。谢谢。
下面是停车场管理系统的代码。
看到的朋友们给点意见,还有就是在文件方面的应用。  谢谢。。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
FILE*fp;
char infile[]="stop.txt";
struct station{
    char carname[90];
    time_t stoptime;
    int sky;
}sta[50];
int num=0;
void spare ();//查空车位
void stop ();//停车
void live ();//离开
void fprintf ();
void face ();
void spare ()
{
    fp=fopen ("stop.txt","r");
    int i;
    if (num>=50)
    {
        printf ("对不起,停车场已满!");
    }
    else
    {
        printf ("以下位置是空的:\n\n");
        for(i=0;i<50;i++)
        {
            if (sta[i].sky ==0)
            {
                printf ("%d号\t",i+1);
            }
        }
    }
}
void stop ()
{
    for (int i=0;i<50;i++)
    {
        if (sta[i].sky==0)
        {
            fp=fopen ("stop.txt","a+");
            printf ("请输入您的车牌号:");
            scanf ("%s",sta[num].carname);
            fputs (sta[num].carname,fp);
            sta[num].stoptime=time(NULL);
            
            printf ("您的停车时间是:");
            printf ("%s",ctime(&sta[num].stoptime));
            printf ("您好!已经完成操作!");
            sta[num].sky = num+1;
            num++;
            fclose (fp);
            break;
        }
    }
}
void live ()
{
    fp=fopen ("stop.txt","r");
    int i;
    time_t ts;
    char carname[90];
    long money;
    printf ("请输入您的车牌号:");
    scanf ("%s",carname);
    for (i=0;i<=50;i++)
    {
        if (strcmp(sta[i].carname,carname)==0)
        {
            ts=time(NULL);
            sta[i].sky=0;
            money=ts-sta[i].stoptime;
            printf ("您的开车时间是:");
            printf ("%s\n",ctime(&ts));
            printf ("%ld\n",money);
            if (money/60>=30&&money<60)
            {
                printf ("您应交3元!祝您一路平安!");
            }
            else if (money/60>=60&&money/60<120)
            {
                printf ("您应交5元!祝您一路平安!");
            }
            else if (money/60>=120&&money<180)
            {
                printf ("您应交10元!祝您一路平安!");
            }
            else if (money/60<30)
            {
                printf ("您应交0元!祝您一路平安!");
            }
            else
            {
                printf ("您应交20元!祝您一路平安!");
            }
        }
    }
}
void fprintf ()
{
    fp=fopen ("stop.txt","r");
    printf ("车牌号\t\t\t\t停车时间\n");
    for (int i=0;i<=num;i++)
    {
        if (sta[i].sky!=0)
        {
            printf ("%s\t\t\t",sta[i].carname);
            printf ("%s",ctime(&sta[i].stoptime));
        }
    }
}
void face ()
{
    int choose;
    printf ("\n\n\n\n\n\n\n\t\t\t\t++++++++++++++++++\n");
    printf ("\t\t\t\t||0.        退出||\n");
    printf ("\t\t\t\t||1.        停车||\n");
    printf ("\t\t\t\t||2.        取车||\n ");
    printf ("\t\t\t\t||3.显示所有数据||\n");
    printf ("\t\t\t\t++++++++++++++++++\n");
    scanf ("%d",&choose);
    switch (choose)
    {
    case 3:
        {
            system ("cls");
            fprintf ();
            system("pause");
            system ("cls");
            face ();
            break;
        }
    case 1:
        {
            system ("cls");
            spare ();
            stop ();
            system("pause");
            system ("cls");
            face ();
            break;
        }
    case 2:
        {
            system ("cls");
            live ();
            system("pause");
            system ("cls");
            face ();
            break;
        }
    case 0:
        break;
    }
}
void main ()
{
    printf ("\n\n\n\n\t\t\t     欢迎进入停车场管理系统\n\n");
    printf ("\n********************************************************************************\n\n\n\n\t\t\t        ");
    system("pause");
    system ("cls");
    for (int i=0;i<50;i++)
        sta[i].sky = 0;
    face ();
}
搜索更多相关主题的帖子: void include station 
2013-04-16 13:02
liu_鹏
Rank: 2
等 级:论坛游民
帖 子:33
专家分:75
注 册:2013-4-16
得分:0 
回复 5楼 zhangqiang16
本来要用文件来存储的。  可是对于文件,我是真的有点搞不懂。  

不懂就发帖。懂了就恢复。
2013-04-17 09:43



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




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

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