| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3194 人关注过本帖, 1 人收藏
标题:已定义结构体,但要在写函数时在函数内需要输入一个新的结构体成员来实现查 ...
只看楼主 加入收藏
C语言渣Bella
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2016-11-13
结帖率:0
收藏(1)
已结贴  问题点数:20 回复次数:5 
已定义结构体,但要在写函数时在函数内需要输入一个新的结构体成员来实现查询,
没个函数都错在与结构体有关的地方,下面是报错。
  void  search()            /***查找函数***/
{   
      
    int i,n,k,w1=1,w2,w3;   
    struct   Hotel   s;   
    n=load();   
    do   
    {   
        w2=-1;   
    do   
    {   
        k=-1;   
        printf("\n\nEnter ID_card that you want to search! ID_card:");                        
        scanf("%s",&s.Client_list.ID_card);                                                      /***输入需要查找的身份证号***/
        for(i=0;i<n;i++)   
            if(strcmp(s.Client_list.ID_card,Room [i].Client_list.ID_card)==0)                    /***串比较函数,若表达式等于0,则两串相等***/
            {  


warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
C:\Program Files\Microsoft Visual Studio\MyProjects\program\pro.c(183) : warning C4024: 'strcmp' : different types for formal and actual parameter 1
C:\Program Files\Microsoft Visual Studio\MyProjects\program\pro.c(183) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
C:\Program Files\Microsoft Visual Studio\MyProjects\program\pro.c(183) : warning C4024: 'strcmp' : different types for formal and actual parameter 2
C:\Program Files\Microsoft Visual Studio\MyProjects\program\pro.c(209) : error C2143: syntax error : missing ';' before 'type'
C:\Program Files\Microsoft Visual Studio\MyProjects\program\pro.c(211) : error C2143: syntax error : missing ';' before 'type'
C:\Program Files\Microsoft Visual Studio\MyProjects\program\pro.c(316) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
C:\Program Files\Microsoft Visual Studio\MyProjects\program\pro.c(316) : warning C4024: 'strcmp' : different types for formal and actual parameter 1
C:\Program Files\Microsoft Visual Studio\MyProjects\program\pro.c(316) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
搜索更多相关主题的帖子: search 身份证号 结构体 
2016-11-13 10:12
xufan
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:232
专家分:804
注 册:2008-10-20
收藏
得分:20 
把完整的代码贴出来吧,现在没弄懂你的意思呢。

~~~~~~我的明天我知道~~~。
2016-11-13 10:28
C语言渣Bella
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2016-11-13
收藏
得分:0 

 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define NUM 100
struct Client
{
    char Name[20];
    int Sex;
    int Age;
    char ID_card[20];                     /***身份证号***/
    int year;
    int month;
    int date;                             /***住店时间***/
};
struct Hotel
{
    int Room_ID;                           /***房间号***/
    char Tel[15];                          /***电话号码***/
    int Price;                             /***住房单价***/
    int Sign;                              /***标记是否为空房间***/
    struct  Client Client_list;            /***实现两个结构体的嵌套***/
}Room[NUM];
 void  search()            /***查找函数***/
{   
      
    int i,n,k,w1=1,w2,w3;   
    struct   Hotel   s;   
    n=load();   
    do   
    {   
        w2=-1;   
    do   
    {   
        k=-1;   
        printf("\n\nEnter ID_card that you want to search! ID_card:");                        
        scanf("%s",&s.Client_list.ID_card);                                                      /***输入需要查找的身份证号***/
        for(i=0;i<n;i++)   
            if(strcmp(s.Client_list.ID_card,Room [i].Client_list.ID_card)==0)                    /***串比较函数,若表达式等于0,则两串相等***/
            {   
                k=i;   
                w2=1;   
                printf_one(k);   
                break;                                                                          /***跳出for循环体***/
            }   
            if(k==-1)   
            {   
                printf("\n\nNo exit!");   
                printf("\n\ndo you try again ?\n\t1).again 2).No and back ");   
                scanf("%d",&w1);   
                if(w1!=1)  menu();                                                              /***返回主菜单***/
            }   
    }while(k==-1&&w1==1);                                                                       /***重试时继续执行循环体***/
      
    if(w2==1)   
    {   
        printf("\n\nDone\n");   
        printf("\nWhat do you want to do?\n\t1).Search another 2).Back to menu ");   
        scanf("%d",&w3);   
        if(w3!=1)  menu();                                                                         /***返回主菜单***/  
    }   
    }while(w3==1);         
2016-11-13 10:54
C语言渣Bella
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2016-11-13
收藏
得分:0 
也就是我在查找函数内定义的struct hotel s 总被报错
2016-11-13 10:55
C语言渣Bella
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2016-11-13
收藏
得分:0 
回复 4楼 C语言渣Bella

 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define NUM 100
struct Client
{
    char Name[20];
    int Sex;
    int Age;
    char ID_card[20];                     /***身份证号***/
    int year;
    int month;
    int date;                             /***住店时间***/
};
struct Hotel
{
    int Room_ID;                           /***房间号***/
    char Tel[15];                          /***电话号码***/
    int Price;                             /***住房单价***/
    int Sign;                              /***标记是否为空房间***/
    struct  Client Client_list;            /***实现两个结构体的嵌套***/
}Room[NUM];
 void  search()            /***查找函数***/
{   
      
    int i,n,k,w1=1,w2,w3;   
    struct   Hotel   s;   
    n=load();   
    do   
    {   
        w2=-1;   
    do   
    {   
        k=-1;   
        printf("\n\nEnter ID_card that you want to search! ID_card:");                        
        scanf("%s",&s.Client_list.ID_card);                                                      /***输入需要查找的身份证号***/
        for(i=0;i<n;i++)   
            if(strcmp(s.Client_list.ID_card,Room [i].Client_list.ID_card)==0)                    /***串比较函数,若表达式等于0,则两串相等***/
            {   
                k=i;   
                w2=1;   
                printf_one(k);   
                break;                                                                          /***跳出for循环体***/
            }   
            if(k==-1)   
            {   
                printf("\n\nNo exit!");   
                printf("\n\ndo you try again ?\n\t1).again 2).No and back ");   
                scanf("%d",&w1);   
                if(w1!=1)  menu();                                                              /***返回主菜单***/
            }   
    }while(k==-1&&w1==1);                                                                       /***重试时继续执行循环体***/
      
    if(w2==1)   
    {   
        printf("\n\nDone\n");   
        printf("\nWhat do you want to do?\n\t1).Search another 2).Back to menu ");   
        scanf("%d",&w3);   
        if(w3!=1)  menu();                                                                         /***返回主菜单***/  
    }   
    }while(w3==1);         
2016-11-13 10:55
C语言渣Bella
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2016-11-13
收藏
得分:0 
回复 2楼 xufan

 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define NUM 100
struct Client
{
    char Name[20];
    int Sex;
    int Age;
    char ID_card[20];                     /***身份证号***/
    int year;
    int month;
    int date;                             /***住店时间***/
};
struct Hotel
{
    int Room_ID;                           /***房间号***/
    char Tel[15];                          /***电话号码***/
    int Price;                             /***住房单价***/
    int Sign;                              /***标记是否为空房间***/
    struct  Client Client_list;            /***实现两个结构体的嵌套***/
}Room[NUM];
 void  search()            /***查找函数***/
{   
      
    int i,n,k,w1=1,w2,w3;   
    struct   Hotel   s;   
    n=load();   
    do   
    {   
        w2=-1;   
    do   
    {   
        k=-1;   
        printf("\n\nEnter ID_card that you want to search! ID_card:");                        
        scanf("%s",&s.Client_list.ID_card);                                                      /***输入需要查找的身份证号***/
        for(i=0;i<n;i++)   
            if(strcmp(s.Client_list.ID_card,Room [i].Client_list.ID_card)==0)                    /***串比较函数,若表达式等于0,则两串相等***/
            {   
                k=i;   
                w2=1;   
                printf_one(k);   
                break;                                                                          /***跳出for循环体***/
            }   
            if(k==-1)   
            {   
                printf("\n\nNo exit!");   
                printf("\n\ndo you try again ?\n\t1).again 2).No and back ");   
                scanf("%d",&w1);   
                if(w1!=1)  menu();                                                              /***返回主菜单***/
            }   
    }while(k==-1&&w1==1);                                                                       /***重试时继续执行循环体***/
      
    if(w2==1)   
    {   
        printf("\n\nDone\n");   
        printf("\nWhat do you want to do?\n\t1).Search another 2).Back to menu ");   
        scanf("%d",&w3);   
        if(w3!=1)  menu();                                                                         /***返回主菜单***/  
    }   
    }while(w3==1);         
2016-11-13 11:13
快速回复:已定义结构体,但要在写函数时在函数内需要输入一个新的结构体成员来实 ...
数据加载中...
 
   



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

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