1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #include <stdio.h> #include <stdlib.h>
#define SLEN 50 #define BUFSIZE 1024
void appen(FILE *source, FILE *dest);
int main(int argc, char *argv[]) { FILE *fp , *ft; char source[SLEN] = "/share/PostLoanData/file.txt"; char targe[SLEN] = "/share/PostLoanData/file2.txt";
char ch; long count, last;
if ((fp = fopen(source, "r")) == NULL) { printf("open source fail %s\n", source); exit(1); }
if ((ft = fopen(targe, "a")) == NULL) { printf("open targe fail %s\n", targe); exit(2); } if (setvbuf(fp, NULL, _IOFBF, BUFSIZE) != 0) { fputs("Can't create input buffer\n", stderr); } appen(fp, ft); if (ferror(fp) != 0) fprintf(stderr, "Error in read file %s \n", source); if (ferror(ft) != 0) fprintf(stderr, "Error in read file %s \n", targe); fclose(fp); fclose(ft); return 0; }
void appen(FILE * source, FILE * dest) { size_t bytes; static char temp[BUFSIZE];
while ((bytes = fread(temp, sizeof(char), BUFSIZE, source)) > 0) fwrite(temp, sizeof(char), bytes, dest); }
|