代码块上 C 语言的隐式函数声明

Implicit Declaration of Function in C on CodeBlocks

你好我正在练习我的C语言知识我正在尝试制作一个简单的计算器但是我遇到了这个警告Implicit Declaration of Function但是我调用的函数已经执行了。我试图用这个 void start(); 修复它,但函数没有执行。

成功执行函数start();但有一个隐式警告:

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

void addition()
{
    int vala, valb, resu;
    system("cls");
    printf("SiMPLE CALCULATOR 1.0a\n");
    printf("ADDITION\n");
    printf("\n");
    printf("Enter the first value of addend: ");
    scanf("%d", &vala);
    printf("Enter the second value of addend: ");
    scanf("%d", &valb);
    resu=vala+valb;
    printf("The sum of %d and %d is: %d\n", vala, valb, resu);
    printf("PRESS [ANY KEY] TO CONTINUE...");
    getch();

    start(); \THIS CODE
}

void start()
{
    char ope;
    system("cls");
    printf("SiMPLE CALCULATOR 1.0a\n");
    printf("What operation will be used:");
    scanf("%s", &ope);

    if (ope == 'a')
    {
        addition();
    }
    else if (ope == 'b')
    {
        printf("bbbbbbbbbbbb\n");
    }
    else
    {
        printf("ccccccccccc\n");
    }

}

int main()
{
    int choices;
    printf("SiMPLE CALCULATOR 1.0a\n");
    printf("choose an option:");
    scanf("%d", &choices);

    if (choices == 1)
    {
        start();
    }

    getch();
    return 0;
}

无法执行函数 void start(); 启动但没有隐式警告:

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

void addition()
{
    int vala, valb, resu;
    system("cls");
    printf("SiMPLE CALCULATOR 1.0a\n");
    printf("ADDITION\n");
    printf("\n");
    printf("Enter the first value of addend: ");
    scanf("%d", &vala);
    printf("Enter the second value of addend: ");
    scanf("%d", &valb);
    resu=vala+valb;
    printf("The sum of %d and %d is: %d\n", vala, valb, resu);
    printf("PRESS [ANY KEY] TO CONTINUE...");
    getch();

    void start(); \THIS CODE
}

void start()
{
    char ope;
    system("cls");
    printf("SiMPLE CALCULATOR 1.0a\n");
    printf("What operation will be used:");
    scanf("%s", &ope);

    if (ope == 'a')
    {
        addition();
    }
    else if (ope == 'b')
    {
        printf("bbbbbbbbbbbb\n");
    }
    else
    {
        printf("ccccccccccc\n");
    }

}

int main()
{
    int choices;
    printf("SiMPLE CALCULATOR 1.0a\n");
    printf("choose an option:");
    scanf("%d", &choices);

    if (choices == 1)
    {
        start();
    }

    getch();
    return 0;
}

start()是在addition()之后声明的,但是在addition()中你调用了start(),所以编译器不知道start()是什么。此外,在 start() 中您还调用了 addition(),因此最好的解决方法是使用前向声明:

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

void start(void); /* forward declaration */
void addition(void); /* forward declaration */

void addition(void)
{
    int vala, valb, resu;
    system("cls");
    printf("SiMPLE CALCULATOR 1.0a\n");
    printf("ADDITION\n");
    printf("\n");
    printf("Enter the first value of addend: ");
    scanf("%d", &vala);
    printf("Enter the second value of addend: ");
    scanf("%d", &valb);
    resu=vala+valb;
    printf("The sum of %d and %d is: %d\n", vala, valb, resu);
    printf("PRESS [ANY KEY] TO CONTINUE...");
    getch();

    start(); 
}

void start(void)
{
    char ope;
    system("cls");
    printf("SiMPLE CALCULATOR 1.0a\n");
    printf("What operation will be used:");
    scanf("%s", &ope);

    if (ope == 'a')
    {
        addition();
    }
    else if (ope == 'b')
    {
        printf("bbbbbbbbbbbb\n");
    }
    else
    {
        printf("ccccccccccc\n");
    }

}

不建议采取允许您从 addition 调用 start 的措施,这会导致潜在的无限递归,只会伪造一个循环。最好放弃 addition 中的 start(); 调用并将 scanf("%s", &ope); 替换为 while (scanf(" %c", &ope) > 0)