Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <Windows.h>
  4.  
  5. int maxx(FILE* f);
  6. int secc(FILE* f, char c);
  7.  
  8. #define _CRT_SECURE_CPP_OVERLOAD_STANDART_NAMES 0
  9. #define _CRT_SECURE_NO_WARNINGS 1
  10.  
  11. int main() {
  12.     char file_name[100], c;
  13.     FILE* f;
  14.  
  15.     printf("Enter file name: ");
  16.     scanf("%s", file_name);
  17.     f = fopen(file_name, "r");
  18.  
  19.     printf("Enter c:");
  20.     scanf("%c", &c);
  21.  
  22.     printf("Maximum number is: %d", maxx(f));
  23.     printf("Number of occurences of %c is %d", c, secc(f, c));
  24.  
  25.     fclose(f);
  26.  
  27.     return 0;
  28. }
  29.  
  30. int maxx(FILE* f) {
  31.     int n;
  32.     int max = 0;
  33.     while (1) {
  34.         int ret = fscanf(f, "%d", &n);
  35.         if (n > max) {
  36.             max = n;
  37.         }
  38.     }
  39.  
  40.     return max;
  41. }
  42.  
  43. int secc(FILE* f, char c) {
  44.     char current_char;
  45.     int n;
  46.  
  47.     while (1)
  48.     {
  49.         current_char = fgetc(f);
  50.         if (feof(f))
  51.         {
  52.             break;
  53.         }
  54.         if (current_char == c) {
  55.             n++;
  56.         }
  57.     }
  58.  
  59.     return n;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement