【C学习-踩坑记录】编译器报错:Implicit declaration of function 'func1' is invalid in C99

本文记录了在C语言编程中遇到的编译错误——隐式声明函数'func1'无效。错误原因在于C99标准下,函数必须在使用前进行声明。解决方法包括在main函数前定义并实现函数,或者先在main函数前声明函数,然后在后面实现它。
摘要由CSDN通过智能技术生成

编译错误

#include <stdio.h>
#include <stdlib.h>
#include "he.h"

static int COUNT = 10;
int main() {
    printf("-----\n");
    while (COUNT > 0) {
        func1();		// **此处方法调用会报 Implicit declaration of function 'func1' is invalid in C99**
//         ^   
        COUNT --;
    }
    return 0;
}
void func1() {
    static int THINGY = 5;
    THINGY ++;
    printf(" thingy is %d, count is %d\n", THINGY, COUNT);
}

解决方案

#include <stdio.h>
#include <stdlib.h>
#include "he.h"

static int COUNT = 10;
void func1() {				//  **将方法定义在 main() 函数上边即可**
    static int THINGY = 5;
    THINGY ++;
    printf(" thingy is %d, count is %d\n", THINGY, COUNT);
}
int main() {
    printf("-----\n");
    while (COUNT > 0) {
        func1();
        COUNT --;
    }
    return 0;
}

or

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值