'Coding with c: warning: incompatible implicit declaration of built-in function ‘exp10’

//SOLVED HERE: https://askubuntu.com/questions/962252/coding-with-c-warning-incompatible-implicit-declaration-of-built-in-function

I don't understand how to compile this.

I've didnt put all of the functions that i've made in this library because all of them work properly, and it's the first time that i have to use math.h

Until now i've compiled like this without issues:

gcc -c -g f.c

gcc -c -g main.c

gcc -o main main.o f.o

I've tried to insert -lm but i don't get how and where it has to be putted.

//header

#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);

//function

#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;
}

//main

#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;
    }

}


Solution 1:[1]

  1. You do need any exp10 and double values for this task.
  2. You have standard C functions like strlen to discover the string length (but is not needed here

Your function can be stripped down to the :

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;
}

Solution 2:[2]

pow(10.0, x) does what exp10(x) does.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Jeremy Caney