#include <stdio.h>
/************************
*name:fwrite.c
*author:QG
*time:2015-05-12
*description:
***************************/
int main()
{
FILE *fp_in;
FILE *fp_out;
char *in_file_name = "./123.txt";
char *out_file_name = "./234.txt";
int a = 1;
int b = 0;
int c = 0;
char c_buf[10];
fp_in = fopen(in_file_name,"r+");
b = fread(c_buf,1,9,fp_in);
c_buf[9] = '\0';
printf("read %d types from 123.txt!\n",b);
printf("read content is :%s!\n",c_buf);
fp_out = fopen(out_file_name,"w+");
c = fwrite(c_buf,1,9,fp_out);
printf("write %d types to 234.txt!\n",c);
a = fclose(fp_in);
fclose(fp_out);
if(a == 0)
{
printf("close OK!\n");
}
else if(a == EOF)
{
printf("close fail!\n");
}
return 0;
}
库函数调用 4--fwrite
最新推荐文章于 2023-12-17 18:19:14 发布
本文演示了使用C语言的fread和fwrite函数进行文件读写操作,通过实例展示了如何从一个文件读取数据并将其写入另一个文件。
524

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



