title: How to fix Segmentation fault in C
body: <p>Hello i wrote my c program which will be run on linux.
  I am trying to make my own shell for linux.
  I have the following code below...</p>
  
  <pre><code>#include &lt;limits.h&gt;
  #include &lt;libgen.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;fcntl.h&gt;
  #define MAX_LINE 80 /* 80 chars per line, per command, should be enough. */
  
  int main(void){
         int i = 0;
         int k = 0;
         int argsCount = 0;
         char inputBuffer[MAX_LINE]; /*buffer to hold command entered */
         int background; /* equals 1 if a command is followed by '&amp;' */
         char *args[MAX_LINE/2 + 1]; /*command line arguments */
         pid_t tpid ;
         pid_t child_pid;
         int child_status;
         char path[PATH_MAX+1];
         char *progpath = strdup(args[0]);
         char *prog = basename(progpath);
         char temp[MAX_LINE];
  }
  </code></pre>
  
  <p>It'is compiling well but when i try to run the code it gives me segmentation fault error</p>
  
  <p>How can i fix it and why i take this error?</p>