title: How do I pass an input response to a function in C
body: <p>I am trying to ask a user what they would like to do in a "shell" that Ive made.  The code that I have is as followed:</p>
  
  <pre><code>    /* Create a char array to hold response */
  char response[80];
  char exit[4] = "Exit";
  
  printf("\n\n     Commands are as followed:");
  printf("\n------------------------------------");
  printf("\n'cd' 'Directory' (Changes Directorys)");
  printf("\n'cp' 'FileName'  (Copys File)");
  printf("\n'Exit'           (Exits the program)");
  printf("\n'ls'             (Displays Info)");
  printf("\n------------------------------------\n\n");
  
  while(strcmp(exit, response) != 0){
  
  /* Ask user for input */
  fputs("$&gt; ", stdout);
  
  /* Flush */
  fflush(stdout);
  
  /* Make sure response is not NULL */
  if ( fgets(response, sizeof response, stdin) != NULL )
  {
      /* search for newline character */
      char *newline = strchr(response, '\n'); 
      if ( newline != NULL )
      {
          /* overwrite trailing newline */
          *newline = '\0'; 
      }
  
      actOnResponse(fs, response); 
   }
  </code></pre>
  
  <p>Now my question deals with the actOnResponse() Function.  I want to pass the response to the function.  In the function I will parse the response and string compare it to the values 'cd', 'cp' and 'ls'. But how do I pass it in? right now, when I run the program, it gives me a segmentation fault (Core Dump).  </p>
  
  <p>Anyone that can point out what I am doing wrong would be great! Thank you.</p>
  
  <p>Here is the actOnResponse() Function:</p>
  
  <pre><code>void actOnResponse(int fs, char *response){
  
  printf("%s" , response);
  }
  </code></pre>