编写一个文件复制程序,提示用户输入源文件名和输出文件名。在向输出文件写入时,程序应当使用ctype.h中定义的toupper()函数将所有的文本转换成大写。使用标准I/O和文本模式。
#include<stdio.h> #include<stdlib.h> #include<ctype.h> int main(void) { int ch; FILE *source,*destination; char source_name[41],destination_name[41]; printf("input the source file's name:"); if ( (source = fopen(gets(source_name),"r")) == NULL) { printf ("Can't open %s\n", source_name); exit(1); } printf("input the destination file's name:"); if ( (destination = fopen(gets(destination_name),"w")) == NULL) { printf ("Can't open %s\n", destination_name); exit(1); } while ((ch = getc(source)) != EOF) putc( toupper(ch), destination ); fclose(source); fclose(destination); printf ("copy finished\n"); return 0; }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题
#include<stdio.h> #include<stdlib.h> #include<ctype.h> int main(void) { int ch; FILE *source,*destination; char source_name[41],destination_name[41]; printf("input the source file's name:"); if ( (source = fopen(gets(source_name),"r")) == NULL) { printf ("Can't open %s\n", source_name); exit(1); } printf("input the destination file's name:"); if ( (destination = fopen(gets(destination_name),"w")) == NULL) { printf ("Can't open %s\n", destination_name); exit(1); } while ((ch = getc(source)) != EOF) putc( toupper(ch), destination ); fclose(source); fclose(destination); printf ("copy finished\n"); return 0; }