Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include"pch.h"
- #include <stdio.h>
- #include <locale.h>
- #include <cstdlib>
- #include <string.h>
- void zamena(char* name, char* text) {
- FILE *output_file;
- fopen_s(&output_file, name, "w");
- const char *alfavit = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
- char *str = new char[256];
- str = text;
- str[strlen(text)+1] = '\0';
- int k = 0;
- char start = ' ';
- while (k != strlen(str)) {
- start = str[k];
- for (int i = 0; i < strlen(alfavit); i++) {
- if (start == alfavit[i]) {
- for (int j = 0; j < strlen(alfavit); j++) {
- if (str[k + 1] == alfavit[j]) {
- for (int c = strlen(str)+1; c >= k+1; c--) {
- if (c == k + 1) {
- str[c] = '?';
- break;
- }
- str[c] = str[c - 1];
- }
- }
- }
- }
- }
- k++;
- }
- fputs(str, output_file);
- fclose(output_file);
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- FILE * myfile;
- char input_name[20], output_name[20];
- printf("Введите имя файла:");
- gets_s(input_name);
- fopen_s(&myfile, input_name, "r");
- if (!myfile)
- {
- printf("Ошибка открытия файла.\n");
- system("pause");
- return NULL;
- }
- int lon = strlen(input_name);
- while ((input_name[lon - 4] != '.') || (input_name[lon - 3] != 't') || (input_name[lon - 2] != 'x') || (input_name[lon - 1] != 't'))
- {
- printf("Ошибка. Неверный формат файла.\n");
- printf("Введите имя файла:");
- gets_s(input_name);
- if (myfile == 0)
- {
- printf("Ошибка открытия файла\n");
- }
- }
- char *text = new char[256];
- fgets(text, 256, myfile);
- fclose(myfile);
- input_name[lon - 3] = 'd';
- input_name[lon - 2] = 'a';
- input_name[lon - 1] = 't';
- zamena(input_name, text);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement