title: I am getting a segmentation fault error on my C program
body: <p>I am getting a segmentation fault in one of the following blocks of code, but I suspect it to be this one, xbits.c:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  
  void itox(int n, char hexstring[]);
  int xtoi(char hexstring[]);
  
  void itox(int n, char hexstring[]) {
      hexstring[2*sizeof(n) + 1];
      int ratio, remainder;
      int i = 0;
      while(ratio  != 0)
      {
  
          ratio = n / 16;
          remainder = n % 16;
          if (remainder == 10){
              hexstring[i] = 'A';
              i++;
          }
          else if (remainder == 11){
              hexstring[i] = 'B';
              i++;
          }
          else if (remainder == 12){
              hexstring[i] = 'C';
              i++;
          }
          else if (remainder == 13){
              hexstring[i] = 'D';
              i++;
          }
          else if (remainder == 14){
              hexstring[i] = 'E';
              i++;
          }
          else if (remainder == 15){
              hexstring[i] = 'F';
              i++;
          }
          else 
              hexstring[i] = remainder;
  
      }   
      i++;
      hexstring[i] = '\0';
  }
  
  int xtoi(char hexstring[]) {
      int i, integer;
      int length = getLength(hexstring);
      for (i = length-2 ; i &gt;= 0 ; i--)
      {
           integer += (int) pow((float) hexstring[i] , (float) i);
      }
  
      return integer;
  }
  
  int getLength (char line[])
  {
      int i;
  
      i=0;
      while (line[i])
          ++i;
      return i;
  }
  </code></pre>
  
  <p>The above relies on a main method, showxbits.c that I have not debugged yet, but when I used a test main method I got a segmentation fault error, and when I use gdb I get the following error.</p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  0x00000000004007ad in itox ()
  </code></pre>
  
  <p>Which leads me to believe that the problem is in itox in the above .c file. The program is supposed to convert an int to hex and a hex back to int. </p>