2017-10-05 69 views
0

//解决这里的不兼容的隐式声明:https://askubuntu.com/questions/962252/coding-with-c-warning-incompatible-implicit-declaration-of-built-in-function内置函数“exp10”

我不知道如何编译此。

我已经didnt把所有的我在这个库中所做的功能,因为它们都正常工作,这是第一次,我必须使用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; 
    } 

} 
+0

尝试增加'-lm'您'gcc'命令 –

+0

@EugeneSh。我已经完成了,但是我不明白在哪里放它 –

+0

'gcc -o main -lm main.o fo' –

回答

0
  1. 你确实需要为这个任务的任何exp10和双重价值。
  2. 您有标准C的功能,如strlen的发现字符串的长度(但这里不需要

你的函数可以精简到:

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

谢谢,但它不是我所需要的 –

+0

@Zeno Raiser易于修改您的typedefs - 请参阅第二个 –

+0

感谢人真的,但我需要了解如何用math.h编译ti,这就是我的问题的要点 –