Advertisement
myamikova9

CLab6VisualStudio

Apr 25th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <locale.h>
  5. #include <cstdlib>
  6. int condition(char symbol){
  7.     return symbol >= 'а' && symbol < 'р' || symbol == 'ё';
  8. }
  9. void writeMat(FILE* input_file, FILE* output_file){
  10.     char mas[80] = "";
  11.     char outputMas[80];
  12.     //mas[0] = '\0';
  13.     while (!feof(input_file)){
  14.         int s = 0;
  15.         fgets(mas, 80, input_file);
  16.         for (int i = 0; mas[i] != '\0'; i++){
  17.             if (!condition(mas[i]))
  18.                 outputMas[s++] = mas[i];
  19.         }
  20.         outputMas[s] = '\0';
  21.         printf("%s", outputMas);
  22.         fprintf_s(output_file, outputMas);
  23.     }
  24.     printf("/n");
  25. }
  26.  
  27. int _tmain(int argc, _TCHAR* argv[])
  28. {
  29.     setlocale(LC_ALL, "Russian");
  30.     FILE* input_file = NULL;
  31.     FILE* output_file = NULL;
  32.     char fileName[20];
  33.     unsigned long n = 0;
  34.     do{
  35.         printf("Введите имя файла: ");
  36.         gets_s(fileName);
  37.         n = strlen(fileName);
  38.     } while (strstr(fileName, ".txt") == NULL);
  39.     fopen_s(&input_file, fileName, "r");
  40.     if (input_file == NULL){
  41.         printf("Файл не может быть открыт или создан\n");
  42.     }
  43.     else printf("Файл успешно открыт\n");
  44.     fileName[n - 3] = 'd';
  45.     fileName[n - 2] = 'a';
  46.     fileName[n - 1] = 't';
  47.     printf("%s\n", fileName);
  48.     fopen_s(&output_file, fileName, "w");
  49.     writeMat(input_file, output_file);
  50.     fclose(input_file);
  51.     fclose(output_file);
  52.     system("pause");
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement