1 solutions
-
0
C :
#include<stdio.h> #define N 80 int appendfile (const char *srcName,const char *dstName); int main() { char srcFilename[N] ; char dstFilename[N]; scanf("%s",srcFilename ); scanf("%s",dstFilename); if(appendfile(srcFilename,dstFilename)) printf("Append succeed!\n"); else printf("Append failed!\n"); return 0; } int appendfile (const char *srcName,const char *dstName) { FILE *fpSrc=NULL,*fpDst=NULL; int ch,rval=1; if((fpSrc=fopen(srcName,"r"))==NULL) goto ERROR; if((fpDst=fopen(dstName,"w"))==NULL) goto ERROR; while((ch=fgetc(fpSrc))!=EOF) { if(fputc(ch,fpDst)==EOF) goto ERROR; } fflush(fpDst); goto EXIT; ERROR: rval=0; EXIT: if(fpSrc!=NULL)fclose(fpSrc); if(fpDst!=NULL)fclose(fpDst); return rval; }
C++ :
#include<cstdio> #include<iostream> using namespace std; int main() { char a[100]={},b[100]={}; cin >> a >> b; FILE *fa,*fb; if ((fa = fopen(a,"r")) == NULL) { printf("Append failed!"); return 0; } if ((fb = fopen(b,"a")) == NULL) { printf("Append failed!"); return 0; } char tmp; while (!feof(fa)) { tmp = fgetc(fa); fputc(tmp, fb); } cout << "Append succeed!"; return 0; }
- 1
Information
- ID
- 509
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By