C 语言中文件的一个问题

来源:百度知道 编辑:UC知道 时间:2024/06/30 07:31:24
putw(int i,FILE *fp)
{char *s;
s =&i;
putc(s[0],fp);putc(s[1],fp);
return(i);
}
那位大侠解释一下
呵呵谢谢了

就是FP指向的内容的前两个复制到S数组的前两个成员

函数名: putw
功 能: 把一字符或字送到流中
用 法: int putw(int w, FILE *stream);
程序例:

#include <stdio.h>
#include <stdlib.h>

#define FNAME "test.$$$"

int main(void)
{
FILE *fp;
int word;

/* place the word in a file */
fp = fopen(FNAME, "wb");
if (fp == NULL)
{
printf("Error opening file %s\n", FNAME);
exit(1);
}

word = 94;
putw(word,fp);
if (ferror(fp))
printf("Error writing to file\n");
else
printf("Successful write\n&