fwrite

来源:互联网 发布:小米平板2最新网络驱动 编辑:程序博客网 时间:2024/05/22 05:15
函数名: fwrite
功  能: 写内容到流中
用  法:fwrite(buffer,size,count,fp);
  (1)buffer:是一个指针,对fwrite来说,是要输出数据的地址。
  (2)size:要读写的字节数;
  (3)count:要进行读写多少个size字节的数据项;
  (4)fp:文件型指针。
程序例:

#include <stdio.h>

struct mystruct
{
  int i;
  char ch;
};

int main(void)
{
   FILE *stream;
   struct mystruct s;

   if ((stream = fopen("TEST.$$$", "wb")) == NULL) /* open file TEST.$$$ */
   {
      fprintf(stderr, "Cannot open output file./n");
      return 1;
   }
   s.i = 0;
   s.ch = 'A';
   fwrite(&s, sizeof(s), 1, stream); /* write struct s to file */
   fclose(stream); /* close file */
   return 0;
}
原创粉丝点击