Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <Windows.h>
- int maxx(FILE* f);
- int secc(FILE* f, char c);
- #define _CRT_SECURE_CPP_OVERLOAD_STANDART_NAMES 0
- #define _CRT_SECURE_NO_WARNINGS 1
- int main() {
- char file_name[100], c;
- FILE* f;
- printf("Enter file name: ");
- scanf("%s", file_name);
- f = fopen(file_name, "r");
- printf("Enter c:");
- scanf("%c", &c);
- printf("Maximum number is: %d", maxx(f));
- printf("Number of occurences of %c is %d", c, secc(f, c));
- fclose(f);
- return 0;
- }
- int maxx(FILE* f) {
- int n;
- int max = 0;
- while (1) {
- int ret = fscanf(f, "%d", &n);
- if (n > max) {
- max = n;
- }
- }
- return max;
- }
- int secc(FILE* f, char c) {
- char current_char;
- int n;
- while (1)
- {
- current_char = fgetc(f);
- if (feof(f))
- {
- break;
- }
- if (current_char == c) {
- n++;
- }
- }
- return n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement