Mike_King

Untitled

Jun 4th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5.     FILE* oFile;
  6.    
  7.     char c, fChar;
  8.     int count = 0, i = 0;
  9.     float percent;
  10.    
  11.     printf("Char: ");
  12.     scanf("%c", &fChar);
  13.    
  14.     oFile = fopen("myfile.txt", "r");
  15.     if(oFile == NULL)
  16.     {
  17.         printf("File not found");
  18.         return 1;
  19.     }
  20.    
  21.     while((c = fgetc(oFile)) != EOF)
  22.     {
  23.         if(c == fChar)
  24.         {
  25.             count++;
  26.         }
  27.         i++;
  28.     }
  29.     fclose(oFile);
  30.    
  31.     printf("\nLen = %d\nCount = %d\n", i, count);
  32.    
  33.     percent = ((float)count / (float)i) * 100;
  34.     printf("Percent = %f", percent);
  35.    
  36.     getch();
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment