Advertisement
fallenangel121

Untitled

Jun 1st, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.86 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <locale.h>
  5. #include "Header.h"
  6.  
  7. void keyboard_input( char* file_name, char *text_input)
  8. {
  9. text_input = malloc(MAX_SIZE * sizeof(char));
  10.  
  11.     FILE* out_file;
  12.     out_file = fopen(file_name, "a+");
  13.  
  14.     if (out_file == NULL)
  15.     {
  16.         printf("Could not open file");
  17.         exit(1);
  18.     }
  19.     while (1)
  20.     {
  21.         if (text_input == NULL)
  22.         {
  23.             printf("Memory not allocated");
  24.             exit(1);
  25.         }
  26.         else
  27.         {
  28.             scanf("\n%[^\n]", text_input);
  29.             fflush(stdin);
  30.  
  31.             if (strcmp(text_input, "end") == 0)
  32.             {
  33.                 fclose(out_file);
  34.                 break;
  35.             }
  36.         }
  37.         fprintf(out_file, "%s\n", text_input);
  38.     }
  39. free(text_input);
  40. }
  41.  
  42. void transliterate(char *file_name)
  43. {
  44.     system("chcp 1251\n");
  45.     setlocale(LC_ALL, "UTF8");
  46.  
  47.     FILE* read_file;
  48.     char str[MAX_SIZE];
  49.     char temp[MAX_SIZE];
  50.  
  51.     read_file = fopen(file_name, "r");
  52.     if (read_file == NULL)
  53.     {
  54.         printf("Could not open file");
  55.         exit(1);
  56.     }
  57.     else if (read_file)
  58.     {
  59.         while (fgets(str, sizeof(str), read_file) != NULL)
  60.         {
  61.  
  62.  
  63.             for (char *p = str, *j = temp; *p; p++) {
  64.                 if (*p == 'a') *p = '\u0430';
  65.                 else if (*p == 'b') *p = '\u0431';
  66.                 else if (*p == 'v') *p = '\u0432';
  67.                 else if (*p == 'g') *p = '\u0433';
  68.                 else if (*p == 'd') *p = '\u0434';
  69.                 else if (*p == 'e') *p = '\u0435';
  70.  
  71.                 else if (*p == 'z')
  72.                 {
  73.                     if (*(p + 1) == 'h')
  74.                     {
  75.                         *p = '\ ';
  76.                         *p = '\b';
  77.                         p++;
  78.                         *p = '\u0436';
  79.                     }
  80.                     else
  81.                     {
  82.                         *p = '\u0437';
  83.                     }
  84.                 }
  85.                 else if (*p == 'i') *p = '\u0438';
  86.                 else if (*p == 'y') *p = '\u0439';
  87.                 else if (*p == 'k') *p = '\u043A';
  88.                 else if (*p == 'l') *p = '\u043B';
  89.                 else if (*p == 'm') *p = '\u043C';
  90.                 else if (*p == 'n') *p = '\u043D';
  91.                 else if (*p == 'o') *p = '\u043E';
  92.                 else if (*p == 'p') *p = '\u043F';
  93.                 else if (*p == 'r') *p = '\u0440';
  94.                 //else if (*p == 's') *p = '\u0441';
  95.                 //else if (*p == 't') *p = '\u0442';
  96.                 else if (*p == 'u') *p = '\u0443';
  97.                 else if (*p == 'f') *p = '\u0444';
  98.                 else if (*p == 'h') *p = '\u0445';
  99.                 else if (*p == 't')
  100.                 {
  101.                     if (*(p + 1) == 's')
  102.                     {
  103.                         *p = '\ ';
  104.                         *p = '\b';
  105.                         p++;
  106.                         *p = '\u0446';
  107.                     }
  108.                     else
  109.                     {
  110.                         *p = '\u0442';
  111.                     }
  112.                    
  113.                 }
  114.                 else if (*p == 'c')
  115.                 {
  116.                     if (*(p + 1) == 'h')
  117.                     {
  118.                         *p = '\ ';
  119.                         *p = '\b';
  120.                         *j = '\u0447';
  121.                         j++;
  122.                     }
  123.                     else
  124.                     {
  125.                         printf("Wrong input");
  126.                         break;
  127.                     }
  128.                 }
  129.                 else if (*p == 's')
  130.                 {
  131.                     if (*(p + 1) == 'h')
  132.                     {
  133.                         *p = '\ ';
  134.                         *p = '\b';
  135.                         p++;
  136.                         *p = '\u0448';
  137.                     }
  138.                     else
  139.                     {
  140.                         *p = '\u0441';
  141.                     }
  142.  
  143.                 }
  144.                 else if (*p == 's')
  145.                 {
  146.                     if (*(p + 1) == 'h' && *(p+2) == 't')
  147.                     {
  148.                         *p = '\ ';
  149.                         *p = '\b';
  150.                         p++;
  151.                         *p = '\u0449';
  152.                     }
  153.                     else
  154.                     {
  155.                         *p = '\u0441';
  156.                     }
  157.  
  158.                 }
  159.                 else if (*p == 'a') *p = '\u044A';
  160.                 //else if (*p == 'y') *p = '\u044C';
  161.                 else if (*p == 'y')
  162.                 {
  163.                     if (*(p + 1) == 'u')
  164.                     {
  165.                         *p = '\ ';
  166.                         *p = '\b';
  167.                         p++;
  168.                         *p = '\u044E';
  169.                     }
  170.                     else
  171.                     {
  172.                         *p = '\u044C';
  173.                     }
  174.  
  175.                 }
  176.                 else if (*p == 'y')
  177.                 {
  178.                 if (*(p + 1) == 'a')
  179.                 {
  180.                     *p = '\ ';
  181.                     *p = '\b';
  182.                     p++;
  183.                     *p = '\u044F';
  184.                 }
  185.                 else
  186.                 {
  187.                     *p = '\u044C';
  188.                 }
  189.  
  190.                 }
  191.                 else if (*p == ' ') *p = ' ';
  192.             }
  193.  
  194.                 printf("%s", temp);
  195.         }
  196.         fclose(read_file);
  197.     }
  198. }
  199.  
  200. /*  FILE* fPtr;
  201.  
  202.     char ch;
  203.  
  204.     fPtr = fopen(file_name, "r");
  205.  
  206.     if (fPtr == NULL)
  207.     {
  208.         printf("Unable to open file.\n");
  209.         printf("Please check whether file exists and you have read privilege.\n");
  210.         exit(EXIT_FAILURE);
  211.     }
  212.  
  213.     printf("File opened successfully. Reading file contents character by character. \n\n");
  214.  
  215.     do
  216.     {
  217.         ch = fgetc(fPtr);
  218.  
  219.         putchar(ch);
  220.  
  221.     } while (ch != EOF);
  222.  
  223.     fclose(fPtr);*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement