69,373
社区成员
发帖
与我相关
我的任务
分享
ch=fgetc(out);
while(ch!=EOF)
{
if(ch!='\n')
i+=1;
ch=fgetc(out);
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=0;
char ch,filename[256];
FILE *in,*out;
if((in=fopen("123.txt","r"))==NULL) //输入文件名 复制123.TXT
{
printf("cannot open the file");
exit(0);
}
printf("Enter the name of copy\n"); //输入文件名 复制123.TXT
scanf("%s",filename);
if((out=fopen(filename,"w"))==NULL)
{
printf("cannot open the file");
exit(0);
}
while(!feof(in))
{
fputc(fgetc(in),out);
}
fclose(out);
if((out=fopen(filename,"r"))==NULL) //"r",以读的方式打开
{
printf("cannot open the file");
exit(0);
}
ch=fgetc(out);
while(ch!=EOF)
{
i+=1;
ch=fgetc(out);
}
printf("%d\n",i);
fclose(in);
fclose(out);
return 0;
}