title: Why does this program for checking if a line is a palindrome return a segfault?
body: <p>I already tried Valgrind with the Valkyrie GUI and Code::Blocks, but I did not really know how to create a project to run it in the debugger, or it just did not work. The <code>printf("here")</code> lines were just for checking were the error was, however, it just sometimes returned "here4". It always returned Segmentation fault: 11, and I cannot see any line where I am adressing memory I do not own.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  int c, length=-1, n, m, palindrome, line[250];
  int half[126];
  int half2[126];
  char string[250];
  char charac[2];
  int main(){
            while(c!=EOF){
                         c=getchar();
                         if(c=='\n' || c==EOF){ /*End of line*/
                                              /*Copies first half of line*/
                                              while(n&lt;=length/2){
                                                                half[n]=line[n];
                                                                ++n;
                                                                 }
                                              /*Copies second half of line*/
                                              for(n=0, m=length; n&lt;=length/2; ++n, --m){
                                                                                       half2[n]=line[m]; 
                                                                                        }
                                              /*Tests if line is palindrome*/
                                              for(palindrome=1, n=0; palindrome &amp;&amp; n&lt;=length/2; ++n){
                                                                                                     if(half[n]!=half2[n])
                                                                                                               palindrome=0;
                                                                                                      }
                                              if(palindrome)
                                                  printf("%s\nis a palindrome.\n", string);
                                              length=-1;
                                              n=0;
                                              m=0;
                                              string[0]=0;
                                              while(n&lt;=125){
                                                           half[n]=0;
                                                           half2[n]=0;
                                                           ++n;
                                                            }
                                              n=0;
                                               }
                         else{
                             /*printf("here4");*/
                             ++length;
                             if(length&gt;500)
                                      break; /*prevent overflow*/
                             line[length]=c;
                             sprintf(charac, "%c", c);
                             strcat(string, charac);
                              }
                          }
            return 0;
             }
  </code></pre>