Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <locale.h>
- #include "Header.h"
- void keyboard_input( char* file_name, char *text_input)
- {
- text_input = malloc(MAX_SIZE * sizeof(char));
- FILE* out_file;
- out_file = fopen(file_name, "a+");
- if (out_file == NULL)
- {
- printf("Could not open file");
- exit(1);
- }
- while (1)
- {
- if (text_input == NULL)
- {
- printf("Memory not allocated");
- exit(1);
- }
- else
- {
- scanf("\n%[^\n]", text_input);
- fflush(stdin);
- if (strcmp(text_input, "end") == 0)
- {
- fclose(out_file);
- break;
- }
- }
- fprintf(out_file, "%s\n", text_input);
- }
- free(text_input);
- }
- void transliterate(char *file_name)
- {
- system("chcp 1251\n");
- setlocale(LC_ALL, "UTF8");
- FILE* read_file;
- char str[MAX_SIZE];
- char temp[MAX_SIZE];
- read_file = fopen(file_name, "r");
- if (read_file == NULL)
- {
- printf("Could not open file");
- exit(1);
- }
- else if (read_file)
- {
- while (fgets(str, sizeof(str), read_file) != NULL)
- {
- for (char *p = str, *j = temp; *p; p++) {
- if (*p == 'a') *p = '\u0430';
- else if (*p == 'b') *p = '\u0431';
- else if (*p == 'v') *p = '\u0432';
- else if (*p == 'g') *p = '\u0433';
- else if (*p == 'd') *p = '\u0434';
- else if (*p == 'e') *p = '\u0435';
- else if (*p == 'z')
- {
- if (*(p + 1) == 'h')
- {
- *p = '\ ';
- *p = '\b';
- p++;
- *p = '\u0436';
- }
- else
- {
- *p = '\u0437';
- }
- }
- else if (*p == 'i') *p = '\u0438';
- else if (*p == 'y') *p = '\u0439';
- else if (*p == 'k') *p = '\u043A';
- else if (*p == 'l') *p = '\u043B';
- else if (*p == 'm') *p = '\u043C';
- else if (*p == 'n') *p = '\u043D';
- else if (*p == 'o') *p = '\u043E';
- else if (*p == 'p') *p = '\u043F';
- else if (*p == 'r') *p = '\u0440';
- //else if (*p == 's') *p = '\u0441';
- //else if (*p == 't') *p = '\u0442';
- else if (*p == 'u') *p = '\u0443';
- else if (*p == 'f') *p = '\u0444';
- else if (*p == 'h') *p = '\u0445';
- else if (*p == 't')
- {
- if (*(p + 1) == 's')
- {
- *p = '\ ';
- *p = '\b';
- p++;
- *p = '\u0446';
- }
- else
- {
- *p = '\u0442';
- }
- }
- else if (*p == 'c')
- {
- if (*(p + 1) == 'h')
- {
- *p = '\ ';
- *p = '\b';
- *j = '\u0447';
- j++;
- }
- else
- {
- printf("Wrong input");
- break;
- }
- }
- else if (*p == 's')
- {
- if (*(p + 1) == 'h')
- {
- *p = '\ ';
- *p = '\b';
- p++;
- *p = '\u0448';
- }
- else
- {
- *p = '\u0441';
- }
- }
- else if (*p == 's')
- {
- if (*(p + 1) == 'h' && *(p+2) == 't')
- {
- *p = '\ ';
- *p = '\b';
- p++;
- *p = '\u0449';
- }
- else
- {
- *p = '\u0441';
- }
- }
- else if (*p == 'a') *p = '\u044A';
- //else if (*p == 'y') *p = '\u044C';
- else if (*p == 'y')
- {
- if (*(p + 1) == 'u')
- {
- *p = '\ ';
- *p = '\b';
- p++;
- *p = '\u044E';
- }
- else
- {
- *p = '\u044C';
- }
- }
- else if (*p == 'y')
- {
- if (*(p + 1) == 'a')
- {
- *p = '\ ';
- *p = '\b';
- p++;
- *p = '\u044F';
- }
- else
- {
- *p = '\u044C';
- }
- }
- else if (*p == ' ') *p = ' ';
- }
- printf("%s", temp);
- }
- fclose(read_file);
- }
- }
- /* FILE* fPtr;
- char ch;
- fPtr = fopen(file_name, "r");
- if (fPtr == NULL)
- {
- printf("Unable to open file.\n");
- printf("Please check whether file exists and you have read privilege.\n");
- exit(EXIT_FAILURE);
- }
- printf("File opened successfully. Reading file contents character by character. \n\n");
- do
- {
- ch = fgetc(fPtr);
- putchar(ch);
- } while (ch != EOF);
- fclose(fPtr);*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement