fprintf不同于printf,它里面有两个参数,第一个参数就是你所想要把内容保存的位置,在你想给某个参数赋值时使用起来方便简单,代码如下:
#include<stdio.h>
#include<stdlib.h>
struct stu
{
int id;
char name[32];
};
int main()
{
FILE *fp;
struct stu s={1,"zhangsan"};
fp=fopen("./d","w");
fprintf(fp,"%d %s\n",s.id,s.name);
fclose(fp);
}
该代码使用文件方式,打开一个文件,使用fprintf对文件进行 写 操作,方便吧!