Advertisement
Guest User

666

a guest
May 21st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.87 KB | None | 0 0
  1. #include"pch.h"
  2. #include <stdio.h>
  3. #include <locale.h>
  4. #include <cstdlib>
  5. #include <string.h>
  6.  
  7.  
  8. void zamena(char* name, char* text) {
  9.       FILE *output_file;
  10.       fopen_s(&output_file, name, "w");
  11.       const char *alfavit = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
  12.       char *str = new char[256];
  13.       str = text;
  14.       str[strlen(text)+1] = '\0';
  15.  
  16.  
  17.       int k = 0;
  18.       char start = ' ';
  19.  
  20.       while (k != strlen(str)) {
  21.           start = str[k];
  22.           for (int i = 0; i < strlen(alfavit); i++) {
  23.               if (start == alfavit[i]) {
  24.                   for (int j = 0; j < strlen(alfavit); j++) {
  25.                       if (str[k + 1] == alfavit[j]) {
  26.                           for (int c = strlen(str)+1; c >= k+1; c--) {
  27.                               if (c == k + 1) {
  28.                                   str[c] = '?';
  29.                                   break;
  30.                               }
  31.                               str[c] = str[c - 1];
  32.                           }
  33.                       }
  34.                   }
  35.  
  36.              
  37.               }
  38.           }
  39.           k++;
  40.       }
  41.  
  42.       fputs(str, output_file);
  43.       fclose(output_file);
  44. }
  45.  
  46.  
  47. int main()
  48. {
  49.     setlocale(LC_ALL, "Russian");
  50.     FILE * myfile;
  51.     char input_name[20], output_name[20];
  52.     printf("Введите имя файла:");
  53.     gets_s(input_name);
  54.     fopen_s(&myfile, input_name, "r");
  55.     if (!myfile)
  56.     {
  57.         printf("Ошибка открытия файла.\n");
  58.         system("pause");
  59.         return NULL;
  60.     }
  61.     int lon = strlen(input_name);
  62.     while ((input_name[lon - 4] != '.') || (input_name[lon - 3] != 't') || (input_name[lon - 2] != 'x') || (input_name[lon - 1] != 't'))
  63.     {
  64.         printf("Ошибка. Неверный формат файла.\n");
  65.         printf("Введите имя файла:");
  66.         gets_s(input_name);
  67.         if (myfile == 0)
  68.         {
  69.             printf("Ошибка открытия файла\n");
  70.         }
  71.     }
  72.  
  73.     char *text = new char[256];
  74.     fgets(text, 256, myfile);
  75.     fclose(myfile);
  76.     input_name[lon - 3] = 'd';
  77.     input_name[lon - 2] = 'a';
  78.     input_name[lon - 1] = 't';
  79.    
  80.  
  81.     zamena(input_name, text);
  82.  
  83.    
  84.     system("pause");
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement