c语言中 fgetc函数、fputc函数实现文件的复制
1、
#include <stdio.h> int main(void) { FILE *sfp; FILE *dfp; int ch; char sfilename[FILENAME_MAX]; char dfilename[FILENAME_MAX]; printf("Please input the sfilename: "); scanf("%s", sfilename); printf("Please input the dfilename: "); scanf("%s", dfilename); if((sfp = fopen(sfilename, "r")) == NULL) printf("\aSource file open failed.\n"); else { if((dfp = fopen(dfilename, "w")) == NULL) printf("\aDestination file open failed.\n"); else { while((ch = fgetc(sfp)) != EOF) fputc(ch, dfp); fclose(dfp); } fclose(sfp); } return 0; }