- #include"stdio.h"
- #include"string.h"
- void main()
- {
- FILE *fp1,*fp2;
- char ch[1000]=" ",c;
- int i=0;
- fp1=fopen("c1.txt","r");
- fp2=fopen("c2.txt","w");
- if(fp1==NULL||fp2==NULL)
- {
- printf("Wrong");
- return;
- }
- /* 统计文件中的字符个数 */
- c=fgetc(fp1);
- while(!feof(fp1))
- {
- i++;
- c=fgetc(fp1);
- }
- rewind(fp1);// 返回头, 否则下面的 fread 读出的空, 尤为重要
- fread(ch,i,1,fp1);// 读出到 ch 数组
- fwrite(ch,i,1,fp2);// 原始文件写入到 c2.txt
- fprintf(fp2,"\n");
- strlwr(ch);// 小写变大写
- fwrite(ch,i,1,fp2);// 转换后的内容写入 c2.txt
- fclose(fp1);
- fclose(fp2);
- }
来源: http://www.bubuko.com/infodetail-2877363.html