title: issue with multifunction utility program in c.
body: <p>The following  program is supposed to read from the command line( using argv[]) and execute either one of three functions:</p>
  
  <p>right(decides whether or not a triangle is a right triangle based on the side length:  by typing mu -r [sidea] [sideb] [sidec]</p>
  
  <p>findtext:(finds the sequence of a string inside of a given file: (ie,"hello") and lists the line number where it found it. </p>
  
  <p>count: (counts the number of tabs, words and backspaces). </p>
  
  <p>Findtext.c is functioning as it should:</p>
  
  <p>for example if i type ./mu -f [string] [file.txt] </p>
  
  <p>it successfully list the file and the line number in the file in which it was found. </p>
  
  <p>but when I run the same code with the -r(right) option it gives me the following segmentation fault: </p>
  
  <p>Program name: ./mu
  3
  Segmentation fault (core dumped)</p>
  
  <p>where am i going wrong in this code? </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  //#include "count.h"
  //#include "right.h"
  //#include "findtext.h"
  
  #define STAND_ALONE 1
  void right(int, char **);
  void count(int, char **);
  void findtext(int, char **);
  #ifdef STAND_ALONE 
  int main(int argc, char *argv[])
  {
  
        printf("\n");
        printf("Can only use one option(-f, -c, -r) at once. sorry!\n");
        printf("\n");
  
  
           printf("Program name: %s\n", argv[0]);
  
      while ((argc &gt; 1) &amp;&amp; (argv[1][0] == '-'))
      {
          switch (argv[1][1])
          {
              case 'f': // findtext.c
                  printf("%s\n",&amp;argv[1][2]);
                  findtext(argc, argv);
                                  break;
  
              case 'r': // right.c
                  printf("%s\n",&amp;argv[1][2]);
                  right(argc, argv);
                  break;
                          case 'c': // count.c
                  printf("%s\n",&amp;argv[1][2]);
                  count(argc,argv);
                  break;
  
              default:
                  printf("Wrong Argument: %s\n", argv[1]);
  
          }
  
          ++argv;
          --argc;
      }
      return (0);
  }
  
  #endif
  
  void right(int argc, char *argv[]){
  int a;
  int b;
  int c;
  int largest;
  int a2;
  int b2;
  int c2;
  
  /*if(argc != 4){
  printf("please enter 3 sides, only \n");
  } */
  
  a = atoi(argv[2]);
  b = atoi(argv[3]);
  c = atoi(argv[4]);
  //printf("argv2:%s ",argv[2]);
  if((a &lt;= 0 )|| (b &lt;= 0) || (c &lt;= 0))
       printf("Only positive values allowed\n"); exit(0);
  
  a2 = (a*a);
  b2 = (b*b);
  c2 = (c*c);
  
  
  if((c &gt; a) &amp;&amp; (c &gt; b))
       largest = c;
  if((b &gt; a) &amp;&amp; (b &gt; c))
       largest = b;
  if((a &gt; b) &amp;&amp; (a &gt; c))
       largest = a;
  
  
  
  if(largest == a){
    printf("HEy hey hey!");
    if((b2 + c2) == a2){ printf("%s %s %s is a right triangle\n",argv[2],argv[3],argv[4]); } 
     else{printf("%s %s %s is not a right triangle\n",argv[3],argv[2],argv[4]);}
   }
  
  if(largest == b){
     printf("HEy");
    if((a2 + c2) == b2){ printf("%s %s %s is a right triangle\n",argv[2],argv[3],argv[4]); } 
     else{printf("%s %s %s is not a right triangle\n",argv[2],argv[3],argv[4]);}
  
   }
  
  if(largest == c){
    printf("yo");
     if((a2 + b2) == c2){ printf("%s %s %s is a right triangle\n",argv[2],argv[3],argv[4]); } 
     else{printf("%s %s %s is not a right triangle\n",argv[2],argv[3],argv[4]);}
  
   }
  
  
  
  
  } /* end method right() */
  
  
  
  void findtext(int argc, char *argv[]){
  FILE *fin;
  char buffer[100];
  int counter;
  char *ptr = buffer;
  char *result;
  
  //if(argc != 3) {printf("Usage: %s filename  argc:%d\n", argv[0], argc); exit(1);}
    fin = fopen(argv[3], "r");
    if(!fin) {printf("Unable to open %s\n", argv[2]); exit(1); }
  
   counter = 0; 
   while (fgets(buffer, 99, fin)){
     counter = counter + 1; 
     if(strstr(ptr,argv[2])){
        printf("%d. %s", counter, ptr);
        printf("\n");
  
       }
  
    }
    fclose (fin);
  
  
  }
  
  
  void count(int argc,  char **argv){
  FILE *fin;
  
  int lcounter = 0;
  int count = 0;
  char name[100];
  char ch;
  
  int word = 0;
  int nchar = 0;
  
  
  
  fin = fopen(argv[1],"r"); // open file
  
  if(fin==0){
  
  printf("Could not find specified file.\n");
  exit(0);
  }
  
  while((ch = getc(fin)) != EOF)
  {
  
    nchar++;
    if(ch == '\n')
      lcounter++;
    if(isspace(ch) || ch == '\t' || ch == '\n')
        word++;
  }
  
  printf("number of characters: %d\n",nchar);
  printf("Lines: %d\n",lcounter);
  printf("words: %d\n",word);
  printf("\n");
  
  fclose(fin);
  
  
  }
  </code></pre>