| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 655 人关注过本帖
标题:为什么每个函数都定义非法
取消只看楼主 加入收藏
教授小黑
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2014-12-16
结帖率:0
收藏
 问题点数:0 回复次数:1 
为什么每个函数都定义非法
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXUSER 10 /* 服务员人数 */
#define SIZE 40 /*菜单*/
struct sysuser{
    char sysname[20]; /*系统管理员帐号*/
    char sysword[8];/*管理员密码*/
    char waiter[20]; /*服务员帐号*/
    char waiterword[8]; /*服务员密码*/
};

struct news{
    char name;
    char sex;
    int age;
    int num;
    int phone;
    char address;
}record[MAXUSER]; /*定义服务员结构体*/
struct menu{
    int num;
    char name;
    int price;
    char kind;
}a[SIZE];

void encrypt(char *pwd);
int checkUserValid(struct sysuser *psu);
void Create();
void browse();
void recompose();
void createmenu();
void browsemenu();
void changemenu();
void foundmenu();
void foodsales();
void customeraverage();
void Createcuetomer();
void browsecustomer();
void changecustomer();
void count();
void ordercuetomer();
void browseorder();
void changeorder();
void foundname();
void foundstyle();
void foundnumber();


void system()
{
            printf("1-用户管理\n");
            printf("2-菜品管理\n");
            printf("3-统计分析\n");
            printf("4-退出\n");
}
void system1()
{
                printf("1-新建用户\n");
                printf("2-浏览用户\n");
                printf("3-修改用户信息\n");
                printf("4-返回\n");
}
void system2()
{
                printf("1-新建菜品\n");
                printf("2-浏览菜品\n");
                printf("3-修改菜品信息\n");
                printf("4-查询菜品\n");
                printf("5-返回\n");
}
void system3()
{
                printf("1-菜品销量排序\n");
                printf("2-顾客人均消费\n");
                printf("3-返回\n");
}
void func1()
{
    int n;
    system1();
    scanf("%d",&n);
    if(n==1){
        Create();
    }
    if(n==2){
        browse();
    }
    if(n==3){
        recompose();
    }
    while(n!=4){
        if(n==1)
           func1();
    }
}
void func2()
{
    int n;
    system2();
    scanf("%d",&n);
    if(n ==1){
        createmenu();
    }
    if(n ==2){
        browsemenu();
    }
    if(n ==3){
        changemenu();
    }
    if(n ==4){
        foundmenu();
    }
    while(n!=5){
        if(n ==1)
            func2();
    }
}
void func3()
{
    int n;
    if(n ==1){
        foodsales();
    }
    if(n ==2){
        customeraverage();
    }
    while(n!=3){
        if(n ==1)
            func3();
    }
}
void user()
{
            printf("1-顾客管理\n");
            printf("2-点餐管理\n");
            printf("3-菜品信息查询\n");
            printf("4-退出\n");
}
void user1()
{
                printf("1-新建顾客信息\n");
                printf("2-浏览顾客信息\n");
                printf("3-修改顾客信息\n");
                printf("4-顾客结账管理\n");
                printf("5-返回\n");
}
void user2()
{
                printf("1-顾客点餐\n");
                printf("2-浏览顾客点餐信息\n");
                printf("3-修改顾客点餐情况\n");
                printf("4-返回\n");
}
void user3()
{
                printf("1-按名称查询\n");
                printf("2-按类别查询\n");
                printf("3-按编号查询\n");
                printf("4-返回\n");
}
void fun1()
{
    int i;
    user1();
    scanf("%d",&i);
    if(i ==1){
        Createcuetomer();
    }
    if(i ==2){
        browsecustomer();
    }
    if(i ==3){
        changecustomer();
    }
    if(i ==4){
        count();
    }
    while(i!=5){
        if(i ==1)
            fun1();
    }
}
void fun2()
{
    int i;
    user2();
    scanf("%d",&i);
    if(i ==1){
        ordercuetomer();
    }
    if(i ==2){
        browseorder();
    }
    if(i ==3){
        changeorder();
    }
    while(i!=4){
        if(i ==1)
            fun2();
    }
}
void fun3()
{
    int i;
    user3();
    scanf("%d",&i);
    if(i ==1){
        foundname();
    }
    if(i ==2){
        foundstyle();
    }
    if(i ==3){
        foundnumber();
    }
    while(i!=4){
        if(i ==1)
            fun3();
    }
}


            



int main()
{
    struct sysuser su;
    int choice1,choice2;
    int m,n,j;
    printf("界面管理\n");
    printf("1-管理员  2-服务员\n");
    scanf("%d",&choice1);
    if(choice1==1){
        printf("输入管理员帐号:");
        scanf("%s\n",su.sysname);
        printf("输入密码:");
        scanf("%s\n",su.sysword);
        if(checkUserValid(&su)==1){
            printf("登陆成功!\n");
            system();
            scanf("%d",&m);
            while( m!=4)
            {
                if(m ==1)
                    func1();
                if(m ==2)
                    func2();
                if(m ==3)
                    func3();
                    system();
                    scanf("%d",&m);
            }
        }

   
    if(choice1==2){
        printf("输入服务员帐号:");
        scanf("%s\n",su.waiter);
        printf("输入密码:");
        scanf("%s\n",su.waiterword);
        if(checkUserValid(&su)==1){
            printf("登陆成功!\n");
            user();
            scanf("%d",&j);
            while(j!=4)
            {
                if(j ==1)
                    fun1();
                if(j ==2)
                    fun2();
                if(j ==3)
                    fun3();
                    user();
                    scanf("%d",&j);
            }
        }
    }

return 0;

}
void encrypt(char *pwd)
{
    int i;
    for(i=0;i<strlen(pwd);i++)
        pwd[i]=pwd[i]^15;
}



int checkUserValid(struct sysuser *psu)
{
    FILE *fp;
    char usr[30],usr1[30],pwd[10];
    char use[30],sue1[30];
    int check=0;
    strcpy(usr,psu->sysname);
    strcpy(pwd,psu->sysword);
    strcpy(use,psu->waiter);
    strcpy(pwd,psu->waiterword);
    encrypt(pwd);


    if((fp=fopen("f1-1.txt","r"))==NUll){
        printf("File open error!\n");
        exit(0);
    }
    strcat(usr," ");strcat(usr,pwd);strcat(usr,"\n");
   
    if((fp=fopen("f1-2.txt","r"))==NUll){
        printf("File open error!\n");
        exit(0);
    }
    strcat(use," ");strcat(use,pwd);strcat(use,"\n");
    while(!feof(fp)){
        fgets(usr1,30,fp);
        if(strcmp(usr,usr1)==0){
            check=1;break;
        }
    }
    while(!feof(fp)){
        fgets(use1,30,fp);
        if(strcmp(use,use1)==0){
            check=1;break;
        }
    }

    if(fclose(fp)){
        printf("Can not close the file!\n");
        exit(0);
    }
    return check;
}

   

void Create() /*创建用户*/
{
    FILE *fp1;
    int i;


    if ((fp1=fopen("d:\\user.dat","wb"))==NULL){
        printf("cannot open file");
        exit(1);
    }
    for(i=0;i<MAXUSER;i++){
        printf("输入姓名:");
        scanf("%s\n",record[i].name);
        peintf("输入性别:");
        scanf("%s\n",record[i].sex);
        printf("输入年龄");
        scanf("%d\n",record[i].age);
        printf("输入电话号码");
        scanf("%d\n".record[i].phone);
        printf("输入家庭住址");
        scanf("%s\n",record[i].address);
        fwrite(&record[i],sizeof(struct news),1,fp1);

    }
        fclose(fp1);
}
void browse() /*浏览信息*/
{
    FILE *fp1;
    int i;
    if((fp1=fopen("d:\\user.dat","rb"))==NULL){
        printf("cannot open file");
        exit(1);
    }
    for(i=0;i<MAXUSER;i++){
        fread(&record[i],sizeof(struct news),1,fp1);
        printf("%s%s%d%d%s\v",record[i].name,record[i].sex,record[i].age,record[i].phone,record[i].address);
    }
        fclose(fp1);
}
void recompose()/*修改用户信息*/
{
    FILE *fp1;
    int n,i;
    char name,sex,address;
    int age,phone;
    if((fp1=fopen("d:\\user.dat","rb+"))==NULL)
    {        
        printf("cannot open file");
        exit(1);
    }
    for(i=0;i<MAXUSER;i++){
        fread(&record[i],sizeof(struct news),1,fp1);
        printf("%s%s%d%d%s\v",record[i].name,record[i].sex,record[i].age,record[i].phone,record[i].address);
    }
    scanf("%d",&n);
    printf("修改第%d条信息",n);
    fseek(fp1,(n-1)*sizeof(struct news),0); /* 定位文件指针指向第n条记录*/
    prinf("输入修改的姓名:");
    scanf("%s",name);
    printf("输入修改的性别:");
    scanf("%s",sex);
    printf("输入修改的年龄:");
    scanf("%d",&age);
    printf("输入修改的电话:");
    scanf("%d",&phone);
    printf("输入修改的地址:");
    scanf("%s",address);
    record[n-1].name=name;
    record[n-1].sex=sex;
    record[n-1].age=age;
    record[n-1].phone=phone;
    record[n-1].address=address;
    fprintf("%s%s%d%d%s\v",record[n-1].name,record[n-1].sex,record[n-1].age,record[n-1].phone,record[n-1].address);
    rewind(fp1);
        fclose(fp1);
}

void createmenu()
{

    FILE *fp;
    int i;


    if ((fp=fopen("d:\\menu.dat","wb"))==NULL){
        printf("cannot open file");
        exit(1);
    }
    for(i=0;i<SIZE;i++){
        printf("输入编号:");
        scanf("%d\n",a[i].num);
        peintf("输入名称:");
        scanf("%s\n",a[i].name);
        printf("输入价格");
        scanf("%d",a[i].price)
        printf("输入类别:");
        scanf("%s",a[i].kind)
        fwrite(&a[i],sizeof(struct menu),1,fp);

    }
        fclose(fp);
}


void browsemenu()
{
   
    FILE *fp;
    int i;
    if((fp=fopen("d:\\menu.dat","rb"))==NULL){
        printf("cannot open file");
        exit(1);
    }
    for(i=0;i<SIZE;i++){
        fread(&a[i],sizeof(struct menu),1,fp);
        printf("%-15d%-15s%-15d%-15s\v",a[i].num,a[i].name,a[i].price,a[i].kind);
    }
        fclose(fp);
}

void changemenu()
{

    FILE *fp;
    int n,i;
    char name,kind;
    int num,price
    if((fp=fopen("d:\\menu.dat","rb+"))==NULL)/*以可读写方式打开文件*/
    {        
        printf("cannot open file");
        exit(1);
    }
    for(i=0;i<SIZE;i++){
        fread(&a[i],sizeof(struct menu),1,fp);
        printf("%-15d%-15s%-15d%-15s\v",a[i].num,a[i].name,a[i].price,a[i].kind);
    }
    scanf("%d",&n);
    printf("修改第%d条信息",n);
    fseek(fp,(n-1)*sizeof(struct menu),0); /* 定位文件指针指向第n条记录*/
    prinf("输入修改的姓名:");
    scanf("%s",name);
    printf("输入修改的年龄:");
    scanf("%d",&num);
    printf("输入修改的价格:");
    scanf("%d",&price);
    printf("输入修改的类别:");
    scanf("%s",kind)
    a[n-1].name=name;
    a[n-1].num=num;
    a[n-1].price=price;
    a[n-1].kind=kind;

    fprintf("%-15d%-15s%-15d%-15d%-15s\v",a[n-1].num,a[n-1].name,a[n-1].price);
    rewind(fp);
        fclose(fp);
}

void foundmenu()
{

    int choice;
    printf("1-按名称查询\n");
    printf("2-按类别查询\n");
    printf("3-按编号查询\n");
    printf("输入你的选择:");
    scanf("%d",&choice);
    if(choice ==1)
        foundname();
    if(choice ==2)
        foundstyle();
    if(choice ==3)
        foundnumber();
}

void foundnumber()
{
    FILE *fp;
    int MenuID;
    bool find_mark=false;
    printf("\n\t\t请输入你要查找的菜名ID:");
    scanf("%d",&MenuID);
     
    printf("\n\t\tID  菜名\t\t价格 \t\t类别\n"); // column headings
    if((fp=fopen("d:\\menu.dat","rb"))==NULL) // open binary file
    {
        printf("Can't open file\n");
        exit(1);
    }
     
    int i=0;
    do
    {
        fseekfp,i*sizeof(struct menu),SEEK_SET);
        fread(&a[i],sizeof(struct menu),1,fp);
        if(a[i].num==MenuID)
        {
            printf("\t\t%d  %5s\t\t%5.1f元  %s\n",a[i].num,a[i].name,a[i].price,a[i].kind);
            find_mark=true;
            break;
        }
         
        i++;
    }while(!feof(fp));
     
    if(!find_mark) printf("\n\t 尊敬的客户:我们餐厅没有你要点的菜喔,你可以试试我们的招牌菜啊^-^.\n");
     
    fclose(fp);
}

void foundname()
{

    FILE *fp;
    int Menuname;
    bool find_mark=false;
    printf("\n\t\t请输入你要查找的菜名:");
    scanf("%s",&Menuname);
     
    printf("\n\t\tID  菜名\t\t价格 类别\n"); // column headings
    if((fp=fopen("d:\\menu.dat","rb"))==NULL) // open binary file
    {
        printf("Can't open file\n");
        exit(1);
    }
     
    int i=0;
    do
    {
        fseekfp,i*sizeof(struct menu),SEEK_SET);
        fread(&a[i],sizeof(struct menu),1,fp);
        if(a[i].name==Menuname)
        {
            printf("\t\t%d  %5s\t\t%5.1f元 %s\n",a[i].num,a[i].name,a[i].price,a[i].kind);
            find_mark=true;
            break;
        }
         
        i++;
    }while(!feof(fp));
     
    if(!find_mark) printf("\n\t 尊敬的客户:我们餐厅没有你要点的菜喔,你可以试试我们的招牌菜啊^-^.\n");
     
    fclose(fp);
}

void foundstyle()
{
    FILE *fp;
    int Menukind;
    bool find_mark=false;
    printf("\n\t\t请输入你要查找的类型:");
    scanf("%s",&Menukind);
     
    printf("\n\t\tID  菜名\t\t价格 类别\n"); // column headings
    if((fp=fopen("d:\\menu.dat","rb"))==NULL) // open binary file
    {
        printf("Can't open file\n");
        exit(1);
    }
     
    int i=0;
    do
    {
        fseek(fp,i*sizeof(struct menu),SEEK_SET);
        fread(&a[i],sizeof(struct menu),1,fp);
        if(a[i].kind==Menukind)
        {
            printf("\t\t%d  %5s\t\t%5.1f元 %s\n",a[i].num,a[i].name,a[i].price,a[i].kind);
            find_mark=true;
            break;
        }
         
        i++;
    }while(!feof(fp));
     
    if(!find_mark) printf("\n\t 尊敬的客户:我们餐厅没有你要点的菜喔,你可以试试我们的招牌菜啊^-^.\n");
     
    fclose(fp);
}
这个代码还没写完,但所有函数都本地定义非法,为什么求大神帮忙解答!
搜索更多相关主题的帖子: 系统管理员 address include 服务员 record 
2015-04-26 10:35
教授小黑
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2014-12-16
收藏
得分:0 
回复 2楼 我爱吃青菜
void recompose()/*修改用户信息*/
{
    FILE *fp1;
    int n,i;
    char name,sex,address;
    int age,phone;
    if((fp1=fopen("d:\\user.dat","rb+"))==NULL)
    {        
        printf("cannot open file");
        exit(1);
    }
    for(i=0;i<MAXUSER;i++){
        fread(&record[i],sizeof(struct news),1,fp1);
        printf("%s%s%d%d%s\v",record[i].name,record[i].sex,record[i].age,record[i].phone,record[i].address);
    }
    scanf("%d",&n);
    printf("修改第%d条信息",n);
    fseek(fp1,(n-1)*sizeof(struct news),0); /* 定位文件指针指向第n条记录*/
    printf("输入修改的姓名:");
    scanf("%s",name);
    printf("输入修改的性别:");
    scanf("%s",sex);
    printf("输入修改的年龄:");
    scanf("%d",&age);
    printf("输入修改的电话:");
    scanf("%d",&phone);
    printf("输入修改的地址:");
    scanf("%s",address);
    record[n-1].name=name;
    record[n-1].sex=sex;
    record[n-1].age=age;
    record[n-1].phone=phone;
    record[n-1].address=address;
    fprintf("%s %s %d %d %s \v",record[n-1].name,record[n-1].sex,record[n-1].age,record[n-1].phone,record[n-1].address);
    rewind(fp1);
        fclose(fp1);
}
关于信息修改,我将文件指针移动到修改的地方,用输入的其他信息替换,之后重新输入,为什么不对?
D:\桌面文件\桌面\Debug\CANTING.CPP(421) : error C2664: 'fprintf' : cannot convert parameter 1 from 'char [17]' to 'struct _iobuf *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
提示信息是这样的
2015-04-26 12:24
快速回复:为什么每个函数都定义非法
数据加载中...
 
   



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

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