Advertisement
Guest User

Untitled

a guest
Jan 8th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define INPUT_FILENAME "input.txt"
  5. #define OUTPUT_FILENAME_1 "output1.txt"
  6. #define OUTPUT_FILENAME_2 "output2.txt"
  7.  
  8. #define MAX_LINE_LEN 256
  9.  
  10. int main(){
  11.  
  12.     int res = 0;
  13.     FILE* fd_input = NULL;
  14.     FILE* fd_output1 = NULL;
  15.     FILE* fd_output2 = NULL;
  16.  
  17.     char str_buff[MAX_LINE_LEN];
  18.     memset(str_buff, '\0', MAX_LINE_LEN * sizeof(char));
  19.  
  20.     fd_input = fopen(INPUT_FILENAME, "r");
  21.     if(!fd_input){
  22.         res = 1;
  23.         goto __exit_l;
  24.     }
  25.  
  26.     fd_output1 = fopen(OUTPUT_FILENAME_1, "w");
  27.     if(!fd_input){
  28.         res = 1;
  29.         goto __exit_l;
  30.     }
  31.  
  32.     fd_output2 = fopen(OUTPUT_FILENAME_2, "w");
  33.     if(!fd_input){
  34.         res = 1;
  35.         goto __exit_l;
  36.     }
  37.  
  38.  
  39.     if(fgets(str_buff, MAX_LINE_LEN, fd_input) != NULL){
  40.         printf("readed line: %s\n", str_buff);
  41.  
  42.     }
  43.     else{
  44.         res = 1;
  45.         goto __exit_l;
  46.     }
  47.     fputs(str_buff, fd_output1);
  48.  
  49.     memset(str_buff, '\0', MAX_LINE_LEN * sizeof(char));
  50.     if(fgets(str_buff, MAX_LINE_LEN, fd_input) != NULL){
  51.         printf("readed line: %s\n", str_buff);
  52.     }
  53.     else{
  54.         res = 1;
  55.         goto __exit_l;
  56.     }
  57.     fputs(str_buff, fd_output2);
  58.  
  59.     __exit_l:
  60.     if(fd_input)
  61.         fclose(fd_input);
  62.     if(fd_output1)
  63.         fclose(fd_output1);
  64.     if(fd_output2)
  65.         fclose(fd_output2);
  66.  
  67.     return res;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement