Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(void)
- {
- FILE* oFile;
- char c, fChar;
- int count = 0, i = 0;
- float percent;
- printf("Char: ");
- scanf("%c", &fChar);
- oFile = fopen("myfile.txt", "r");
- if(oFile == NULL)
- {
- printf("File not found");
- return 1;
- }
- while((c = fgetc(oFile)) != EOF)
- {
- if(c == fChar)
- {
- count++;
- }
- i++;
- }
- fclose(oFile);
- printf("\nLen = %d\nCount = %d\n", i, count);
- percent = ((float)count / (float)i) * 100;
- printf("Percent = %f", percent);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment