0
Follow
0
View

The list defines a lookup function error

zcc493841274 注册会员
2023-02-27 15:52
I don't know if this problem has been solved for you, if not:
< br / > if you have already solved the problem, very hope you can share your solution, write blogs, Put related links in the comments section to help more people ^-^
medicmagic 注册会员
2023-02-27 15:52
< div class = "md_content_show e397 data - v - 3967" = "" >

ok, thank you

latashu 注册会员
2023-02-27 15:52

Other errors have also been marked, in the stu() function.

dai_feng0118 注册会员
2023-02-27 15:52

In your code, the findss() function is not declared before it is called. The declaration can be placed at the beginning of a header file or code file, or it can be defined in another function before the main() function. Here is an example:


Node* findss(); // 函数声明

int main() {
  // ...
}

Node* findss() { // 函数定义
  // ...
}

Alternatively, you can place the definition of the findss() function before the definition of the main() function:


Node* findss() {
  // ...
}

int main() {
  // ...
}

Before it is defined, the C compiler needs to know the return type and argument type of the function so that it can be type-checked when compiling other code.

cz42202046 注册会员
2023-02-27 15:52

That means if I made a mistake there, the rest is right, isn't it?

Haody_Du 注册会员
2023-02-27 15:52

Modified as follows, please refer to the comments for reference:

#include 
#include 
#include 
typedef struct stu
{
    int  ID;// 学号
    char name[10];  //姓名
    char day[15];  //日期
    char ma[5];    //健康码
    char fangshi[10];   //返校方式
    char chaci[20];    //车次
    char leixing[10];      //风险类型
    char tujing[20];      // 途经城市
    char hesuanshijian[10]; // 核酸时间
    char jieguo[5];
    struct stu* next;
}student;

//节点
typedef struct Node
{
    student stu;    //学生 
    struct Node* pNext;
}Node;
Node *g_pHead = NULL;  //头结点

//************修改 函数声明移动到此处

void help();       //系统帮助信息
void addstu();     //录入学生信息
void printfstu();  //打印学生信息
void yemian();     //功能页面
void savestu();    //保存学生信息
void readstu();    //读取学生信息
Node* findss();    //查找学生信息
void modifystu();  //修改学生信息
int  countstu();   //统计学生信息  //修改 统计学生信息函数未声明

//-----------------------------主函数----------------------
int main()
{
    int choice,t;
        while(1)
        {
            yemian();
            scanf("%d",&choice);
            switch (choice) 
            {
                case 0:
                    help();
                    break;
                
                case 1:
                    readstu();
                     break; 
                  
                case 2:
               {
                    Node* p = findss();
                    if( p!=NULL )
                    {
                        printf("学号:%d\t姓名:%s\t健康码类型:%s\t核酸结果:%s",p->stu.ID,
                                                        p->stu.name,p->stu.ma,p->stu.jieguo);
                    }
                    else
                    {
                        printf("没有找到该学生信息");
                    }
                    break;
                }
                case 3:
                    break;
                    
                case 4:
                    printf("学生总人数为:%d\n",countstu());
                    break;
                
                case 5:
                    break;
        
                case 6:
                    printfstu();
                    break;
                    
                case 7:
                    savestu();
                    break;
                    
                case 8:
                    addstu();
                    break;
                
                case 9:
                    printf("成功退出!欢迎下次使用!\n");
                    return 0;
                    break; 
         
                default:printf("请输入正确的序号(0~8)!\n");
            }
            system("pause");
            system("cls");
        }
    return 0;
}

//-----------------------------函数区---------------------

void yemian()
{
    printf(" *******************************************************\n\n");
        printf(" *                    疫情防控管理系统                   *\n");
        printf(" *******************************************************\n\n");
        printf("***********************系统功能菜单***********************\n");
        printf("**********************请选择功能编号************************\n");
        printf("    -------------------------     ------------------------\n");
        printf("    *****************************************************\n");
        printf("    * 0.系统帮助及说明      * * 1.读取学生信息          *\n");
        printf("    *****************************************************\n");
        printf("    * 2.查询学生信息        * * 3.修改学生信息          *\n");
        printf("    *****************************************************\n");
        printf("    * 4.统计学生信息        * * 5.删除学生信息        *\n");
        printf("    *****************************************************\n");
        printf("    * 6.打印学生信息        * * 7.保存当前学生信息      *\n");
        printf("    *****************************************************\n");
        printf("    * 8.疫情问卷调查填报    * * 9.退出系统               \n");
        printf("    *****************************************************\n");
        printf("    -------------------------    ------------------------\n");
} 

void help()
{
    printf("-------------------帮助信息-------------------\n\n");
    printf("1.输入序号1~9、并回车,选择相应功能。\n");
    printf("2.身份证默认18位。\n");
    printf("4.退出程序之前要保存当前信息。\n");
    printf("5.由于格式问题,在文件中直接更改的话可能导致部分数据乱码。\n");
    printf("6.功能2中的查询信息可以根据姓名、城市、健康码类别(红码/黄码)核酸阳性查询。\n");
}

//添加学生信息 
void addstu ()
{
    //创建新的节点 
    Node *pNewNode=(Node*)malloc(sizeof(Node));
    pNewNode->pNext=NULL;
    
    //头插法
    if(g_pHead==NULL)
    {
        g_pHead = pNewNode;
    }
    else
    {
        pNewNode->pNext=g_pHead;
        g_pHead = pNewNode; 
    }
    printf("请输入学号\n");
    scanf("%d", &(pNewNode->stu.ID));

    printf("请输入姓名\n");
    scanf(" %s",pNewNode->stu.name);
    
    printf("请输入到校日期,例如:yyyy-mm-dd\n");
    scanf(" %s",pNewNode->stu.day);
    
    printf("请选择健康码类型,红码填A,黄码填B,绿码填C\n");
    scanf(" %s",pNewNode->stu.ma);  //scanf(" %c",pNewNode->stu.ma);        修改
    
    printf("请选择返校方式(单选题)\nA火车/动车/高铁\nB飞机\nC自驾\nD其他\n");
    scanf(" %s",pNewNode->stu.fangshi);  //scanf(" %c",pNewNode->stu.fangshi);   修改

    printf("请输入乘坐车次\n");
    scanf(" %s",pNewNode->stu.chaci);
    
    printf("请选择风险类型(单选题)\nA无\nB途径高风险地区\nC居住在高风险地区\nD密接高危人群\n");
    scanf(" %s",pNewNode->stu.leixing);
    
    printf("请输入途经城市(包括家和学校所在城市,城市间用空格分隔)\n");
    getchar();                                                             //修改
    gets(pNewNode->stu.tujing);  //scanf(" %s",pNewNode->stu.tujing);      //修改
    
    printf("请输入最近一次做核酸时间,格式为:yyyy-nn-dd\n");
    scanf(" %s",pNewNode->stu.hesuanshijian);
    
    printf("请选择最近一次核酸结果,—表示阴性,+表示阳性\n");
    scanf(" %s",pNewNode->stu.jieguo);
    
    printf("学生信息录入完成\n");
}

//打印当前信息
void printfstu() 
{
    Node* pNode = g_pHead;
    while (pNode != NULL)
    {
        student stu = pNode->stu;
        printf("学号:%d\n", stu.ID);
        printf("姓名:%s\n", stu.name);
        printf("日期:%s\n", stu.day);
        printf("健康码:%s\n", stu.ma);
        printf("返校方式:%s\n", stu.fangshi);
        printf("车次:%s\n", stu.chaci);
        printf("风险类型:%s\n", stu.leixing);
        printf("途经城市:%s\n", stu.tujing);
        printf("核酸时间:%s\n", stu.hesuanshijian);
        printf("核酸结果:%s\n", stu.jieguo);
        printf("-----------------------------\n\n");
        pNode = pNode->pNext;
    }
}
//保存学生信息 
void savestu()
{
    //打开文件 
    FILE* fp=fopen("疫情防控登记单.txt","w");
    
    if(fp==NULL)
    {
        printf("打开文件失败\n");
        return ;
    }
    //遍历链表 
    Node* p=g_pHead;
    while(p!=NULL)
    {
        student stu = p->stu;
        fwrite(&p->stu,1,sizeof(student),fp);
        p = p->pNext; 
    }

    //关闭文件
    fclose(fp);
    printf("保存文件成功"); 
}


//读取学生信息 
void readstu()
{
    //打开文件
    FILE *fp=fopen("疫情防控登记单.txt","r"); 
    if(fp==NULL)
    {
        printf("打开文件失败\n");
        return ;
    }
    
    //读文件
    student stu;
    while (fread(&stu,1,sizeof(student),fp))
    {
        //创建新的节点
        Node *pNewNode = (Node*)malloc(sizeof(Node)); 
        pNewNode->pNext=NULL;
        
        memcpy(pNewNode,&stu,sizeof(student));
        
        //头插法 
        if(g_pHead==NULL)
        {
        g_pHead = pNewNode;
        }
        else
        {
        pNewNode->pNext=g_pHead;
        g_pHead = pNewNode;
        }
     } 
    
    //关闭文件
     fclose(fp);
     printf("读取文件成功\n");
}


//统计学生信息 
int countstu()
{
    int count=0;
    
    //遍历链表
    Node* p=g_pHead;
    while(p!=NULL)
    {
        count++;
        p=p->pNext;
    } 
    
    return count;
}

//查找学生信息
Node* findss()
{
    char key[20];
    printf("请输入学生的 姓名/黄码/红码/途径城市/核酸结果(其中一项):\n");
    scanf("%s",key);

    Node*p=g_pHead;
    while(p!=NULL)
    {
        if(!strcmp(p->stu.name,key)   || !strcmp(p->stu.ma,key) ||
           !strcmp(p->stu.tujing,key) || !strcmp(p->stu.jieguo,key))
        //if( strcmp(p->stu.name,key)|| strcmp(p->stu.ma,key) || strcmp(p->stu.tujing,key)) 修改
        {
            return p;
        }
        p=p->pNext;
     }
    //没找到返回NULL
    return NULL;
}

About the Author

Question Info

Publish Time
2023-02-27 15:52
Update Time
2023-02-27 15:52

Related Question