C语言中,编程实现将文本文件file1.dat中的内容复制到文本文件file2.dat中去,同时将小写字母转换成大写字
展开全部
#include "stdio.h"
#include <stdlib.h>
void main()
{
FILE *in,*out;
char ch;
if((in=fopen("file1.dat","r+"))==NULL)
{
printf("can,t open thie file!");
exit(0);
}
if((out=fopen("file2.dat","w+"))==NULL)
{
printf("can,t open thie file!");
exit(0);
}
while(!feof(in))
{
ch=fgetc(in);
char ch1=ch+'A'-'a';
fputc(ch1,out);//从infile中取入字符放到outfile文件中去
}
while(!feof(out))
{
ch=fgetc(out);
putchar(ch);
out++;
}
fclose(in);
fclose(out);
}
#include <stdlib.h>
void main()
{
FILE *in,*out;
char ch;
if((in=fopen("file1.dat","r+"))==NULL)
{
printf("can,t open thie file!");
exit(0);
}
if((out=fopen("file2.dat","w+"))==NULL)
{
printf("can,t open thie file!");
exit(0);
}
while(!feof(in))
{
ch=fgetc(in);
char ch1=ch+'A'-'a';
fputc(ch1,out);//从infile中取入字符放到outfile文件中去
}
while(!feof(out))
{
ch=fgetc(out);
putchar(ch);
out++;
}
fclose(in);
fclose(out);
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include "stdio.h"
main()
{
FILE *fp1,*fp2;
char ch;
if((fp1=fopen("file1.dat","rb"))==NULL)
{
printf("Can't open file1.dat!\n");
return;
}
if((fp2=fopen("file2.dat","wb"))==NULL)
{
printf("Can't open file2.dat!\n");
return;
}
while(!feof(fp1))
{
ch=fgetc(fp1);
if(ch>='a'&&ch<='z') ch-='a'-'A';
if(ch!=-1) fputc(ch,fp2);
}
fcloseall();
}
main()
{
FILE *fp1,*fp2;
char ch;
if((fp1=fopen("file1.dat","rb"))==NULL)
{
printf("Can't open file1.dat!\n");
return;
}
if((fp2=fopen("file2.dat","wb"))==NULL)
{
printf("Can't open file2.dat!\n");
return;
}
while(!feof(fp1))
{
ch=fgetc(fp1);
if(ch>='a'&&ch<='z') ch-='a'-'A';
if(ch!=-1) fputc(ch,fp2);
}
fcloseall();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
引用heartfleet的回答:
#include "stdio.h"
#include <stdlib.h>
void main()
{
FILE *in,*out;
char ch;
if((in=fopen("file1.dat","r+"))==NULL)
{
printf("can,t open thie file!");
exit(0);
}
if((out=fopen("file2.dat","w+"))==NULL)
{
printf("can,t open thie file!");
exit(0);
}
while(!feof(in))
{
ch=fgetc(in);
char ch1=ch+'A'-'a';
fputc(ch1,out);//从infile中取入字符放到outfile文件中去
}
while(!feof(out))
{
ch=fgetc(out);
putchar(ch);
out++;
}
fclose(in);
fclose(out);
}
#include "stdio.h"
#include <stdlib.h>
void main()
{
FILE *in,*out;
char ch;
if((in=fopen("file1.dat","r+"))==NULL)
{
printf("can,t open thie file!");
exit(0);
}
if((out=fopen("file2.dat","w+"))==NULL)
{
printf("can,t open thie file!");
exit(0);
}
while(!feof(in))
{
ch=fgetc(in);
char ch1=ch+'A'-'a';
fputc(ch1,out);//从infile中取入字符放到outfile文件中去
}
while(!feof(out))
{
ch=fgetc(out);
putchar(ch);
out++;
}
fclose(in);
fclose(out);
}
展开全部
不用return 0?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询