Advertisement
Anton0093

6_19

May 19th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 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 trans(char* name, FILE *file_input) {
  9.     FILE *file_output;
  10.     char stroka[579];
  11.     fopen_s(&file_output, name, "w");
  12.     fgets(stroka, 548, file_input);
  13.     int i = 0;
  14.     do {
  15.         if (((stroka[i + 1] >= '0') && (stroka[i + 1] <= '9')) && ((stroka[i] >= '0') && (stroka[i] <= '9'))) {
  16.             int a = (int)stroka[i];
  17.             int a1 = (int)stroka[i + 1];
  18.             int b = '0';
  19.             int p = (a - b)*(a1 - b);
  20.             fprintf_s(file_output, "%i", p);
  21.         }
  22.         else { fprintf_s(file_output, "%c", stroka[i]); }
  23.         i++;
  24.     } while (stroka[i] != '\0');
  25.     fclose(file_output);
  26. }
  27.  
  28.  
  29. int main()
  30. {
  31.     setlocale(LC_ALL, "Russian");
  32.     FILE * myfile;
  33.     char input_name[20];
  34.     printf("Введите имя файла: ");
  35.     gets_s(input_name);
  36.     unsigned long lon = 0;
  37.     do
  38.     {
  39.         printf("Введите имя файла с расшираением <<.txt>>: ");
  40.         gets_s(input_name);
  41.         lon = strlen(input_name);
  42.     }
  43.     while (strstr(input_name, ".txt") == NULL);
  44.     fopen_s(&myfile, input_name, "r");
  45.     if (input_name == NULL)
  46.     {
  47.         printf("Файл не может быть открыт\n");
  48.     }
  49.     else
  50.         printf("Файл успешно открыт\n");
  51.     input_name[lon - 3] = 'd';
  52.     input_name[lon - 2] = 'a';
  53.     input_name[lon - 1] = 't';
  54.     printf("Создан файл: %s\n", input_name);
  55.     trans(input_name, myfile);
  56.     fclose(myfile);
  57.     system("pause");
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement