Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <Windows.h>
- int countOccurence(char symbol, char* arr, int arrSize);
- int getCharCode(char ch, char* arrWithCodes, int arrSize);
- int main()
- {
- FILE* file = NULL;
- char filename[100];
- printf("Enter filename: ");
- scanf("%s", &filename);
- file = fopen(filename, "r");
- if (file == NULL) {
- printf("Error, while opening file: %s", filename);
- system("Pause");
- return -1;
- }
- char ch;
- int chCounter = 0;
- // map
- char symbols[95];
- int symbols_occurs[95];
- int symbols_dec[95];
- for (int i = 0; i < 94; i++) {
- symbols[i] = (char)(i + 32);
- symbols_occurs[i] = 0;
- symbols_dec[i] = i + 32;
- }
- while ( (ch = fgetc(file)) != EOF) {
- chCounter++;
- int curr = getCharCode(ch, symbols, 95);
- symbols_occurs[curr] += 1;
- }
- // Prints statistic
- printf("Symbol => ASCII-DEC => ASCII-HEX => Count: \n");
- for (int i = 0; i < 94; i++) {
- if (symbols_occurs[i] != 0) {
- printf("%c => %d => %x => %d \n", symbols[i], symbols_dec[i], symbols[i], symbols_occurs[i]);
- }
- }
- fclose(file);
- char srchCh;
- printf("Type character, to search for: ");
- scanf(" %c", &srchCh);
- int srchChCode = getCharCode(srchCh, symbols, 95);
- int srchChOccurs = symbols_occurs[srchChCode];
- printf("Frequence: %f ", (((double)srchChOccurs / (double)chCounter)) );
- char chToBeSWP;
- char chToSWP;
- printf("Which character you want to swap and with what? ");
- scanf(" %c %c", &chToBeSWP, &chToSWP);
- FILE* outputFile = fopen("output.txt", "w");
- while ()
- system("Pause");
- return 0;
- }
- int countOccurence(char symbol, char* arr, int arrSize) {
- int result = 0;
- for (int i = 0; i < arrSize; i++) {
- if (arr[i] == symbol) {
- result++;
- }
- }
- return result;
- }
- int getCharCode(char ch, char* arrWithCodes, int arrSize) {
- for (int i = 0; i < arrSize; i++) {
- if (arrWithCodes[i] == ch) {
- return i;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement