首页 > 试题广场 >

编写一个文件复制程序,提示用户输入源文件名和输出文件名。在向

[问答题]

编写一个文件复制程序,提示用户输入源文件名和输出文件名。在向输出文件写入时,程序应当使用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;
}

发表于 2018-05-05 22:00:49 回复(0)