用fread和fwrite实现文件拷贝
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<head.h>
int main(int argc, const char *argv[])
{FILE* fp=fopen("./11.txt","w+");FILE* fp1=fopen("./12.txt","w");if(NULL==fp){ERR_MSG("fopen");return -1;}if(NULL==fp1){ERR_MSG("fopen");return -1;}char a[]="aaaaa";fwrite(a,sizeof(a),1,fp);fseek(fp,0,SEEK_SET);char b[10]="";fread(b,sizeof(a),1,fp);fwrite(a,sizeof(a),1,fp1);fclose(fp);fclose(fp1);return 0;
}
用fgets计算文件有几行
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<head.h>
int main(int argc, const char *argv[])
{FILE* fp=fopen("./13.txt","r");if(NULL==fp){ERR_MSG("fopen");return -1;}char a[10]="";int count=0;while(1){if(fgets(a,sizeof(a),fp)==NULL)break;count++;}printf("%d\n",count);return 0;
}
标准IO输入输出函数总结