Не работает метод hex-dec - C (СИ)
Формулировка задачи:
Доброго времени суток! Помогите разобраться с кодом. Компилятор ругается вот таким:
Код:
gcc -Wall -o "main" "main.c" (в каталоге: /home/ironhide/books/С/rus/Kernigan_C_programming) /tmp/cc6h1NYT.o: In function `htoi': main.c:(.text+0xee): undefined reference to `pow' main.c:(.text+0x12f): undefined reference to `pow' main.c:(.text+0x170): undefined reference to `pow' main.c:(.text+0x1b1): undefined reference to `pow' main.c:(.text+0x1f2): undefined reference to `pow' /tmp/cc6h1NYT.o:main.c:(.text+0x233): more undefined references to `pow' follow collect2: выполнение ld завершилось с кодом возврата 1 Сборка завершилась с ошибкой.
#include <stdio.h>
#include <string.h>
#include <math.h>
int htoi(const char*);
int main(){
const char* n="34DF3";
printf("%d", htoi(n));
return 0;
}
int htoi(const char* hexn){
int hexnCounter=0, hexnLen, n=0;
typedef enum {false, true} bool;
bool prefix;
prefix=(hexn[0]=='0'&&(hexn[1]=='x'||hexn[1]=='X'))?true:false;
hexnLen=strlen(hexn);
if(prefix){
hexnCounter+=2;
hexnLen-=2;
}
hexnLen--;
for(;hexn[hexnCounter];hexnCounter++,hexnLen--){
switch(hexn[hexnCounter]){
case 'a':case 'A':n+=10*pow(16,hexnLen);break;
case 'b':case 'B':n+=11*pow(16,hexnLen);break;
case 'c':case 'C':n+=12*pow(16,hexnLen);break;
case 'd':case 'D':n+=13*pow(16,hexnLen);break;
case 'e':case 'E':n+=14*pow(16,hexnLen);break;
case 'f':case 'F':n+=15*pow(16,hexnLen);break;
default: n+=(hexn[hexnCounter]-'0')*pow(16,hexnLen);break;
}
}
return n;
}Решение задачи: «Не работает метод hex-dec»
textual
Листинг программы
1<<(hexnLen*0x10)