Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Apple Xcode
- #include <stdio.h>
- #include <stdlib.h>
- #ifdef BYTE
- #undef BYTE
- #endif
- #define BYTE unsigned char
- int main (int argc, const char * argv[])
- {
- // insert content from file 2 into the file 1
- char *the_file_name_1 = "/Users/.../Desktop/bkpf_01.txt";
- char *the_file_name_2 = "/Users/.../Desktop/bkpf_02.txt";
- BYTE *the_buffer_2;
- long the_size;
- FILE *the_file_1, *the_file_2;
- // open file-1 for update, file-2 for read
- the_file_1 = fopen(the_file_name_1, "a+");
- the_file_2 = fopen(the_file_name_2, "rb");
- if (the_file_1 == NULL)
- {
- perror("erro na abertura do ficheiro 1");
- return EXIT_FAILURE;
- }
- if (the_file_2 == NULL)
- {
- perror("erro na abertura do ficheiro 2");
- return EXIT_FAILURE;
- }
- // get size of file-2
- fseek(the_file_2, 0, SEEK_END);
- the_size = ftell(the_file_2);
- rewind(the_file_2);
- // allocate buffer, read-in file-2
- the_buffer_2 = (BYTE *)malloc((size_t)the_size);
- fread(the_buffer_2, the_size, 1, the_file_2);
- // write the buffer to (end of) file-1
- fwrite(the_buffer_2, the_size, 1, the_file_1);
- // clean-up and close
- free(the_buffer_2);
- fclose(the_file_1);
- fclose(the_file_2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement