title: segmentation fault (core dumped) error in C program
body: <p>I tried to compile and run the following program to reverse a string using the gcc compiler for linux but it shows the error : segmentation fault (core dumped).I even tried to debug using gdb but it didn't help. The program given below firstly inputs t which is the number of test cases.I tested the program with 3 test cases but after taking the 2nd input from user, the compiler shows error.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  char* strrev(char*);
  
  int main(int argc, char *argv[])
  {
          int t,i=0,temp=0;
          char *str[10],*rev[10];
          scanf("%d",&amp;t); //input the number of test cases
          while(i&lt;t)
          {
              scanf("%s",str[i]);
              i++;
          }
          while(temp&lt;t) //reverse the string and display it
          {
             rev[temp]=strrev(str[temp]);
             printf("%s \n",rev[temp]);
             temp++;
          }
      return 0;
      getchar();
  }
  </code></pre>
  
  <p>Function to reverse the string:</p>
  
  <pre><code>char *strrev(char *str) 
  {
  
      int i = strlen(str)-1,j=0;
  
      char ch;
      while(i&gt;j)
      {
          ch = str[i];
          str[i]= str[j];
          str[j] = ch;
          i--;
          j++;
      }
      return str;
  } 
  </code></pre>