title: Segmentation fault in C. What is the reason?
body: <p>I am getting segmentation fault in C and I have no idea what is the reason. As far as I know segmentation fault occurs when system run our of memory. I checked my loops and they seem to have clear termination conditions. Thus, I am confused what causes my code to crash. As I checked this fault should occurs in mygetline or readlines functions.
  Is there any debugger that I can use to find our why program crashes?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #define MAXLINE 100
  #define MAXLINENUM 10
  
  int readlines(char *lines[]);
  int mygetline(char line[]); /* getline: read a line into s, returns length */
  void writelines(char *lines[], int nlines);
  
  int main()
  {
  
  int i = 0;
  
  char *lines[MAXLINE];
  i = readlines(lines);
  writelines(lines, i);
  
  return 0;
  }
  
  int mygetline(char line[]){
      int i, c;
  
      for(i = 0; i &lt; MAXLINE-1 &amp;&amp; (c = getchar()) != '\n' &amp;&amp; c != EOF; i++){
          line[i] = c;
      }
      line[i] = '\0';
      return i;
  }
  
  int readlines(char *lines[]){
  
      int i, c;
      i = 0;
  
      while((c = mygetline(lines++)) &gt; 0 &amp;&amp; i &lt; MAXLINENUM){ //line[i]
          i++;
      }
  
      lines[--i] = '\0';
      return i;
  }
  
  void writelines(char *lineptr[], int nlines) {
      int i;
      for (i = 0; i &lt; nlines; i++) 
          printf("%s\n", lineptr[i]);
  }
  </code></pre>