刷题
思维导图

#include <myhead.h>
int main(int argc, const char *argv[])
{
FILE *fp=fopen("./cat.txt","r");
if(fp==NULL)
{
ERROR("fopen error\n");
}
printf("文件打开成功\n");
FILE *fp1=fopen("./cpy.txt","w");
if(fp1==NULL)
{
ERROR("fopen error\n");
}
char ch;
while(1)
{
if((ch=fgetc(fp))==EOF)
{
break;
}
if(fputc(ch,fp1)==EOF)
{
printf("fputc error\n");
return -2;
}
}
printf("文件复制完成\n");
if(fclose(fp)==EOF)
{
ERROR("fclose error\n");
}
if(fclose(fp1)==EOF)
{
ERROR("fclose error\n");
}
return 0;
}
#include <myhead.h>
int main(int argc, const char *argv[])
{
FILE *fp=fopen("./cat.txt","r");
if(fp==NULL)
{
ERROR("fopen error");
}
int ch;
int count=0;
while(1)
{
if((ch=fgetc(fp))==EOF)
{
printf("fgetc error\n");
break;
}
if(ch=='\n')
{
count++;
}
}
printf("这个文件一共有%d行\n",count);
if(fclose(fp)==EOF)
{
ERROR("fclose error");
}
return 0;
}


279

被折叠的 条评论
为什么被折叠?



