对"operations"的未定义引用

Undefined reference to "operations"

本文关键字:引用 未定义 operations      更新时间:2023-10-16

当我用代码块编译这个程序时,我得到了对"运算"的未定义引用。我只包含了程序中显示错误的一部分。如何解决此错误?

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main()
{
     ---------------------
     ---------------------
     while(1)
     {
          printf("Choose from one of the following options :n");
          printf("1. XXXn 2. YYYn 3. ZZZn");
          scanf("%d", &choice);
          switch(choice)
         {
             case 1:
             case 2:
             case 3:
             case 4:operations();
             return 0;
             break;
            default: printf("Wrong option choose againn");
            return 1;
       }
    }
    void operations()
    {
         while(1)
         {
            printf("Choose from one of the following options :n");
            printf("1. XXXn2. YYYn3. ZZZn");
                scanf("%d",&choice_of_options);
        switch(choice_of_options)
            {
                ---------
                    ---------
            }
        }
     }
}

您不应该在main函数中实现operations

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
 void operations()
    {
         while(1)
         {
            printf("Choose from one of the following options :n");
            printf("1. XXXn2. YYYn3. ZZZn");
                scanf("%d",&choice_of_options);
        switch(choice_of_options)
            {
                ---------
                    ---------
            }
        }
     }
int main()
{
     ---------------------
     ---------------------
     while(1)
     {
          printf("Choose from one of the following options :n");
          printf("1. XXXn 2. YYYn 3. ZZZn");
          scanf("%d", &choice);
          switch(choice)
         {
             case 1:
             case 2:
             case 3:
             case 4:operations();
             return 0;
             break;
            default: printf("Wrong option choose againn");
            return 1;
       }
    }
}

如果按照显示的消息进行,则需要main中调用函数operations之前声明它的原型。

void operations(void);
int main(void){
...
// then your code