title: Problem finding the ratio of frequency of a word to total no of words in a text file in c
body: <pre><code>#include&lt;conio.h&gt;
  #include&lt;stdio.h&gt;
  #include&lt;iostream.h&gt;
  #define NULL 0
  
  
  
  int main()
  {
      char name[20],c;
      int nw=0;
      int j=0;
      int t=0;
      char s[] = "newas";  // find the frequency of this word in abc.txt
      char p[5];
      FILE *fpt;
      //printf("Enter the name of file to be checked:- ");
      //gets(name);
      fpt=fopen("abc.txt","r");
      if (fpt==NULL)
      {
          printf("ERROR - can/'t open file %s",name);
          getch();
          exit(0);
      }
      else
      {
          while ((c=getc(fpt))!=EOF)
          {
              switch(1)
              {
                  case 1:
                      if (c==' ')
                      {
  point:
                          while((c=getc(fpt))==' ');
  
                          if (c!=' ')
                              nw=nw+1;
                          // if(c==' ')
                              // nw--;
                          if(j &lt; 5)
                              p[j++] = c;
                          printf("\n %c ",p[j]);
                          if(j == 5)
                          {
                              if(p == s)
                              {
                                  t++;
                                  j = 0;    
                              }
                          }
                      }
  
                      if(c==' ')
                      {
                          j = 0;
                          goto point;
                      }
              }
          }
      }
      printf("\n The no. of words is %d. ",nw);
      printf("\n Freq of words %s is %d. ",s,t);
      getch();
  }
  </code></pre>
  
  <p>The code above code is giving right answer for the total number of words but is not giving the right value of frequency of a particular word [s in given code], please comment on this, how to calculate frequency of a particular word in a text file.</p>