Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define INPUT_FILENAME "input.txt"
- #define OUTPUT_FILENAME_1 "output1.txt"
- #define OUTPUT_FILENAME_2 "output2.txt"
- #define MAX_LINE_LEN 256
- int main(){
- int res = 0;
- FILE* fd_input = NULL;
- FILE* fd_output1 = NULL;
- FILE* fd_output2 = NULL;
- char str_buff[MAX_LINE_LEN];
- memset(str_buff, '\0', MAX_LINE_LEN * sizeof(char));
- fd_input = fopen(INPUT_FILENAME, "r");
- if(!fd_input){
- res = 1;
- goto __exit_l;
- }
- fd_output1 = fopen(OUTPUT_FILENAME_1, "w");
- if(!fd_input){
- res = 1;
- goto __exit_l;
- }
- fd_output2 = fopen(OUTPUT_FILENAME_2, "w");
- if(!fd_input){
- res = 1;
- goto __exit_l;
- }
- if(fgets(str_buff, MAX_LINE_LEN, fd_input) != NULL){
- printf("readed line: %s\n", str_buff);
- }
- else{
- res = 1;
- goto __exit_l;
- }
- fputs(str_buff, fd_output1);
- memset(str_buff, '\0', MAX_LINE_LEN * sizeof(char));
- if(fgets(str_buff, MAX_LINE_LEN, fd_input) != NULL){
- printf("readed line: %s\n", str_buff);
- }
- else{
- res = 1;
- goto __exit_l;
- }
- fputs(str_buff, fd_output2);
- __exit_l:
- if(fd_input)
- fclose(fd_input);
- if(fd_output1)
- fclose(fd_output1);
- if(fd_output2)
- fclose(fd_output2);
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement