1 条题解
-
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
信息
- ID
- 3070
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者