c语言编程:编写程序,实现文本文件的复制。从一个文件中逐个字符输出,将其中的小写字母转换成大写字母

2024-12-01 14:23:44
推荐回答(2个)
回答(1):

#include
void main()
{ int c;
FILE *fp,*tp;
char fname1[]={ "f.txt" },fname2[]={ "file.txt" },cc;
if ( fp=fopen(fname1,"r") )
{ if ( tp=fopen(fname2,"w+") )
{ while ( 1 )
{ c=fgetc(fp); if ( c==EOF ) break;
cc=c; if ( (cc>='a')&&(cc<='z') ) cc=cc-'a'+'A';
fputc(cc,tp);
}
fclose(tp);
} else printf("无法建立文件%s\n",fname2);
fclose(fp);
} else printf("无法打开文件%s\n",fname1);
}

回答(2):

#include
int main()
{char c;
FILE *fp1,*fp2;
fp1=fopen("0.txt","r");
fp2=fopen("00.txt","w");
while(!feof(fp1))
{c=fgetc(fp1);
if(c>='a'&&c<='z')c-=32;
fputc(c,fp2);
}
fclose(fp1);
fclose(fp2);
return 0;
}