title: Segmentation Fault--Signal 11
body: <p>I am relatively new to programming (a few months in) and am trying out some USACO problems. 
  When I submitted my program, it said this:</p>
  
  <blockquote>
    <p>Run 1: Execution error: Your program (`palsquare') exited with
            signal #11 (segmentation violation [maybe caused by accessing
            memory out of bounds, array indexing out of bounds, using a bad
            pointer (failed open(), failed malloc), or going over the maximum
            specified memory limit]). The program ran for 0.005 CPU seconds
            before the signal. It used 2168 KB of memory. </p>
  </blockquote>
  
  <p>I can't find any dereferenced null pointers, which i initially thought was the problem.</p>
  
  <p>Here is my code (I programmed in C language)</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;assert.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;math.h&gt;
  
  int ispal( char *square )
  {
      char *temp;
  
      temp = square + strlen( square ) - 1;
      for( temp = square + strlen( square ) - 1; square &lt; temp; square++, temp-- )
      {
          if( *square != *temp )
              return 0;
      }
      return 1;
  }
  
  void convert( char *square, int n, int base )
  {
      int len;
  
      if( n == 0 ) 
      {
          square = "";
          return;
      }
  
      convert( square, n / base, base );
  
      len = strlen( square );
      square[len] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[n % base];
      square[len + 1] = '\0';
  }
  
  int main()
  {
      char square[100];
      char temp[100];
      int i, base;
      FILE *fin, *fout;
  
      fin = fopen( "palsquare.in", "r" );
      fout = fopen( "palsquare.out", "w" );
  
      fscanf( fin, "%d", &amp;base );
      for( i = 1; i &lt;= 300; i++ ) 
      {
          convert( square, i * i, base );
          if( ispal( square ) ) 
          {
              convert( temp, i, base );
              fprintf( fout, "%s %s\n", temp, square );
          }
      }
  
      return 0;
  }
  </code></pre>