title: how to solve undefined reference error in C?
body: <p>I'm very new to C programming and studying on K&amp;R C Programming Language book. I'm trying to write a program converts hexadecimal numbers to decimal numbers repeatedly and want to use a function in my code. There are some problems prevent me from understanding C. I've read about them but not clearly understand.</p>
  
  <p>I want to read input with length max 4, but as I understand scanf() doesn't limit length although the length of char array is 4. So I tried to eliminate non-integer characters with a for loop. Is this ok? What is the proper way of getting input from users? I don't want to use <code>while((cr=getchar())!=EOF)</code>.</p>
  
  <p>When I run the program, I get an error message:"undefined reference to 'convert'". How should I define functions?</p>
  
  <p>I use Code::Blocks 16.01 and MinGW. </p>
  
  <p>Here is my try:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include&lt;math.h&gt;
  
  #define LENGTH 4
  
  int convert (char hex[]);
  int result,validLength,j;
  char input[LENGTH];
  
  int main(){
  
      while(1){
  
          printf("Please enter valid hexadecimal number %d length:",LENGTH);
          scanf("%c", input);  //reading to char array
  
          for(j=0;j&lt;LENGTH;j++)   // buffer
              if(input[j] &gt; 48 &amp;&amp; input[j] &lt; 58)
                  validLength++; 
  
  
          printf("Here is the decimal result: %d", convert(input[validLength]));
  
          validLength=0;
  
      }
  
      int convert(char hex[]){
  
          int t;
  
          for(t=0; t &lt; validLength; t++)
              result= result+ hex[t]*(pow(16,(validLength-t)));
  
          return result;
  
      }
  
      return 0;
  }
  </code></pre>