Its basically telling me it doesn't know wth the pow() function is. But at the top of the file, I have #include<math.h> so shouldn't that work? And right after I have the #include, I declared the function definition of bintodec, so that isn't the problem either.

int bintodec(char* array){

   int result = 0;
   double power = 0.0;
   int i;
   int temp;
   double temp2;

   for (i = 0; array[i] != '\0'; i++){
      temp = (int)array[i];
      temp2 = temp * pow(2.0, power);
      result += (int)temp2;
      power = power + 1;
   }

   return result;

You have to link the math library.

que?

I thought the math library was there by default. Like stdio.h.
edit: yeah, it is, I just needed to use the -lm flag

que?

I thought the math library was there by default. Like stdio.h.

You can include as many .h files as you want, but if the compiler doesn't link the library defined in the .h file by default, it can't see it.
GCC for example it doesn't. gcc -Wall -pedantic myfilesource.c -lm -o myprogramfile will let the compiler know.

Yeah, thanks. Here's the code I was working on, in case anyone is interested. It finds the max value that can fit in float and double. If no one is interested, whatever, wasn't the purpose of this thread anyway.

#include <stdio.h>
#include <math.h>

double bintodec(char* array);

int main(){
   char maxfloat[] = "1111111111111111\0";
   char maxDouble[] = "11111111111111111111111111111111\0";

   printf("Max value float can hold: %lf, max double can hold: %lf", bintodec(m\
axfloat), bintodec(maxDouble));

   return 0;

}

double bintodec(char* array){

   double result = 0.0;
   double power = 0.0;
   int i;
   int temp;
   double temp2;

   for (i = 0; array[i] != '\0'; i++){
      temp = 1;
      temp2 = temp * pow(2.0, power);
      printf("the int = %d, power = %f and result for bin digit is %lf\n", temp\
      ,power,temp2);
      result += temp2;
      power = power + 1;
 }

   return result;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.