使用 c 编码 : warning: incompatible implicit declaration of built-in function ‘exp10’

标签 c compilation warnings

//在这里解决:https://askubuntu.com/questions/962252/coding-with-c-warning-incompatible-implicit-declaration-of-built-in-function

我不明白如何编译它。

我没有把我制作的所有函数都放入这个库中,因为它们都可以正常工作,而且这是我第一次必须使用 math.h

到目前为止,我已经这样编译了,没有任何问题:

gcc -c -g f.c

gcc -c -g main.c

gcc -o main main.o f.o

我尝试插入 -lm 但我不知道如何以及在何处放置它。

//标题

#include<math.h>
#define MAX 5

typedef enum {FALSE, TRUE} bool;

typedef enum {ERROR=-1, OK=1} status;

status parse_int(char s[], int *val);

//函数

#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include"f.h"


status parse_int(char s[], int *val) {

    int l, val_convertito = 0, val_momentaneo = 0;
    for(l = 0; s[l] != '\0'; l++);
    for(int i = 0; s[i] != '\0'; i++) {
        if(s[i] >= '0' && s[i] <= '9') {
            val_momentaneo = ((int) (s[i]-48)) * ((int)exp10((double)l--)); 
            val_convertito += val_momentaneo;
            *val = val_convertito;
        } else return ERROR;
    }

    return OK;
}

//主要

#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include"f.h"


int main() {

    int val_con, *val, ls;
    char s_int[ls];

    printf("Inserisci la lunghezza della stringa: ");
    scanf("%d", &ls);

    printf("\n");
    printf("Inserisci l'intero da convertire: \n");
    scanf("%s", s_int);

    val = &val_con;

    status F8 = parse_int(s_int, val);

    switch(F8) {
        case OK:  printf("Valore convertito %d\n", val_con);
                  break;
        case ERROR: printf("E' presente un carattere non numerico.\n");
                    break;
    }

}

最佳答案

  1. 此任务确实需要任何 exp10 和 double 值。
  2. 您可以使用 strlen 等标准 C 函数来发现字符串长度(但此处不需要

您的函数可以精简为:

int str_to_int(const char* value)
{
    int res = 0;
    while (*value)
    {
        if (!isdigit(*value)) return -1;
        res *= 10;
        res += *value++ - '0';

    }
    return res;
}

status str_to_int1(const char* value, int *res)
{
    *res = 0;
    while (*value)
    {
        if (!isdigit(*value)) return ERROR;
        *res *= 10;
        *res += *value++ - '0';

    }
    return OK;
}

关于使用 c 编码 : warning: incompatible implicit declaration of built-in function ‘exp10’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46590763/

相关文章:

c++ - cudaMalloc 和 cudaMemcpy 的包装函数

c++ - 在库中使用 __gcov_flush 不会强制其他模块生成 .gcda 文件

java - 未经检查将 'java.lang.object' 转换为 'java.util.list '

c - 如何编译 Linux C 程序在另一台 Linux 机器上运行?

c - 错误 '->' 的类型参数无效(有 'tree' )

C# 在内存中编译并创建内存组件类型的实例

c++ - Visual Studio 不编译特定文件

c# - 每个文件在 ASP.NET MVC 站点上的初始加载都很慢

c++ - 禁用关于在派生类的复制构造函数中显式初始化基构造函数的警告

c++ - 为什么 GCC 在将未初始化的 volatile 指针转换到 `void` 时发出警告?