| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2108 人关注过本帖
标题:桌台管理系统删除出现问题
只看楼主 加入收藏
小编程家
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-6-14
收藏
 问题点数:0 回复次数:0 
桌台管理系统删除出现问题
#include <stdio.h>
#include<stdlib.h>
#include <string.h>
#define MAX 20
struct table
{
    int ID;//编号
    char name[20];//名字
    char Num[40];//人数
    char FL[20];//分类
    char JJ[20];//简介
}a[100];
typedef struct LNode
{
    struct table tableData;
    struct LNode *next;
}LNode;
FILE *fp;
void menu();
void save(m)
{
    int i;
    fp=fopen("table.dat","wb");
    if(fp==NULL)
    {
        printf("connot open file");
        return;
    }
    for(i=0;i<m;i++)
    {
        if(fwrite(&a[i],sizeof(struct table),1,fp)!=1)
        {   
            printf("保存失败!\n");
            return ;
        }
        printf("保存信息成功\n");
        system("pause");
    }fclose(fp);
}
   
void initiative(LNode *L,int m)
//初始化
{
    int i;
    LNode *p,*q;
    q=L;
    for(i=0;i<m;i++)
    {
        system("cls");  
        printf("请输入第%d个桌台的信息:\n",i+1);
        p=(LNode *)malloc(sizeof(LNode));
        if(p==NULL)
            return;
        fflush(stdin);
        printf("桌台编号:");scanf("%d",&p->tableData.ID);
        printf("桌台名:");scanf("%s",&p->tableData.name);
        printf("桌台人数:");scanf("%s",&p->tableData.Num);
        printf("桌台分类:");scanf("%s",&p->tableData.FL);
        printf("桌台简介:");scanf("%s",&p->tableData.JJ);
        a[i]=p->tableData;
        p->next=NULL;
        q->next=p;
        p=p->next;
        fflush(stdin);
    }
    save(m);
    system("cls");
}
int load()
{
    FILE*fp;
    int i=0;
    if((fp=fopen("table.dat","r"))==NULL)
    {
        printf ("cannot open file\n");
        exit(0);
     }
    else
    {
        do
        {
            fread(&a[i],sizeof(struct table),1,fp);
            i++;
        }while(feof(fp)==0);
    }
    fclose(fp);
    return(i-1);
}
void browse()
//浏览
{
    int i,m=load();
    printf("---------------------------------------------------------------------");
    printf("\n桌台号\t桌台名\t桌台人数\t桌台分类\t桌台简介\n");
    printf("---------------------------------------------------------------------");
    for(i=0;i<m;i++)
    {
        printf("\n%4d",a[i].ID);
        printf("\t%s",a[i].name);
        printf("\t%s",a[i].Num);
        printf("\t%4s",a[i].FL);
        printf("\t%4s",a[i].JJ);
        printf("\n--------------------------------------------------------------");   
    }
    printf("\n");
}
int add(LNode *L)
{
    LNode *p,*s;
    int j=0,m=load(),x,i;
    p=L;
    while(p!=NULL&&j<m)
    {
        p=p->next;
        j++;
    }
    j=0;
    printf("请输入你要添加的职工人数:\n");
    scanf("%d",&x);
    for(i=m;i<m+x;i++)
    {
        s=(LNode*)malloc(sizeof(LNode));
        if(s==NULL)
            return 0;
        printf("桌台编号:");scanf("%d",&s->tableData.ID);
        printf("桌台名:");scanf("%s",&s->tableData.name);
        printf("桌台人数:");scanf("%s",&s->tableData.Num);
        printf("桌台分类:");scanf("%s",&s->tableData.FL);
        printf("桌台简介:");scanf("%s",&s->tableData.JJ);
        if(s->tableData.ID<=m)
        {
            printf("你的输入有误");
            system("pause");
            menu();
        }
    a[i]=s->tableData;
    s->next=NULL;
    s=s->next;
    j++;
    fflush(stdin);
    }
    save(m+j);
    return 1;   
}
void Delete(LNode *L)
{   
    int j=0,m;
    char s;
    LNode *p,*q;
    p=L;
        printf("请输入删除的桌台号");
        scanf("%d",&m);
    while(p->next!=NULL)
    {
        if(p->tableData.ID==m)
            break;
        else
            p=p->next;
    }
    q=p->next;
    p->next=p->next->next;
    j=0;
    for(;p;)
    {
        p->tableData.ID--;
        a[j]=p->tableData;
        p=p->next;
        j++;
    }
    free(q);
    save(j);
}

void cancel()
{
    char a;
    FILE *fp;
    fp=fopen("zhuotai.dat","w");
    printf("是否退出(y/n)");
    getchar();
    a=getchar();
    if(a=='y'||a=='Y')
    {
        fclose(fp);
    exit(0);
    }
    else
        menu();
}
void inquire()
{
    int j=0,m=load();
    char b[20];
    printf("请输入你要查询的餐桌名字:\n");
    scanf("%s",&b);
        for(j=0;j<m;j++)
        {
            if(strcmp(b,a[j].name)==0)
            {
                printf("---------------------------------------------------------------------");
                printf("\n桌台号\t桌台名\t桌台人数\t桌台分类\t桌台简介\n");
                printf("---------------------------------------------------------------------");
                printf("\n%4d",a[j].ID);
                printf("\t%s",a[j].name);
                printf("\t%s",a[j].Num);
                printf("\t%s",a[j].FL);
                printf("\t%s",a[j].JJ);
                printf("\n--------------------------------------------------------------");   
            }
        }
}
void modify()
{

    int j=0,m=load();
    char b[20];
    printf("请输入你要修改的餐桌名字:\n");
    scanf("%s",&b);
        for(j=0;j<m;j++)
        {
            if(strcmp(b,a[j].name)==0)
            {
                printf("---------------------------------------------------------------------");
                printf("\n桌台号\t桌台名\t桌台人数\t桌台分类\t桌台简介\n");
                printf("---------------------------------------------------------------------");
                printf("\n%4d",a[j].ID);
                printf("\t%s",a[j].name);
                printf("\t%s",a[j].Num);
                printf("\t%s",a[j].FL);
                printf("\t%s",a[j].JJ);
                printf("\n--------------------------------------------------------------\n");   
                printf("把此桌台ID改为:\n");
                scanf("%d",&a[j].ID);
                printf("把此桌台名改为:\n");
                scanf("%d",&a[j].name);
                printf("把此桌台人数改为:\n");
                scanf("%d",&a[j].Num);
                printf("把此桌台分类改为:\n");
                scanf("%d",&a[j].FL);
                printf("把此桌台简介改为:\n");
                scanf("%d",&a[j].JJ);

            }
        }
        save(m);
}
void menu()
//菜单
{
    int a,m,j;
    LNode L;
    L.next=NULL;
    system("cls");   
    printf("\t\t  菜单\t\t\n");
    printf("\t\t1.初始化桌台\t\t\n");
    printf("\t\t2.查询桌台\t\t\n");
    printf("\t\t3.浏览桌台\t\t\n");
    printf("\t\t4.添加桌台\t\t\n");
    printf("\t\t5.删除桌台\t\t\n");
    printf("\t\t6.修改桌台\t\t\n");
    printf("\t\t7.退出系统\t\t\n");
    printf("请选择:\n");
    scanf("%d",&a);
    switch(a)
    {
    case 1 :
        printf("请输入你要初始化桌台的个数:\n");
        scanf("%d",&m);
        initiative(&L,m);
        browse();
        system("pause");
        break;
    case 2 : inquire();break;
    case 3 :
            browse();
            system("pause");
            break;
    case 4 :
        add(&L);
    case 5:
        
            Delete(&L);
        break;
    case 7:
        cancel();
        break;
    case 6:
        modify();break;
    default :
        printf("选择错误,请重输");
        system("pause");
        menu();
    }
}

void main()
//主函数
{
   
    while(1)
        menu();
}
删除是始终要中断
搜索更多相关主题的帖子: 管理系统 include return file 
2015-06-16 13:36
快速回复:桌台管理系统删除出现问题
数据加载中...
 
   



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

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