Advertisement
myamikova9

CLab6-Xcode

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