c语言 13-8 、13 - 9、13 -10
13-8、
#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) { putchar(ch); fputc(ch, dfp); } fclose(dfp); } fclose(sfp); } return 0; }
13 - 9、
#include <stdio.h> #include <ctype.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(toupper(ch), dfp); fclose(dfp); } fclose(sfp); } return 0; }
13-10、
#include <stdio.h> #include <ctype.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("\aSfilename open failed.\n"); else { if((dfp = fopen(dfilename, "w")) == NULL) printf("\aDfilename open failed.\n"); else { while((ch = fgetc(sfp)) != EOF) fputc(tolower(ch), dfp); fclose(dfp); } fclose(sfp); } return 0; }