c - 使用 fwrite() 将结构写入文件错误 688

标签 c

错误:“fwrite”的参数 1 的类型不兼容 /usr/include/stdio.h:688: 注意:应为“const void * restrict”,但参数类型为“struct oseba” make: *** [E1041080] 错误 1

struct oseba{
char baza[100];
int telefonska;
char ime[10];
char priimek[20];
int dan;
int mesec;
int leto;

};

children ,我需要帮助!怎么了?

------------------------写---------------- ----

FILE*file=fopen("fhfh.dat","wb");
if(file!=NULL)
{   fwrite(oseba1,sizeof(struct oseba),1,file);
    fclose(file);
}

最佳答案

您需要将一个指针 传递给该结构。也就是说,

fwrite(&oseba1, sizeof(struct oseba), 1, file);

但是请注意,通过将structs 写入二进制文件,很有可能文件因此保存will not be portable ,例如您甚至不能在程序的 32 位和 64 位编译之间或从平台到另一个平台共享它。

关于c - 使用 fwrite() 将结构写入文件错误 688,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35925995/

相关文章:

c - _通用 : multiple types to a single value?

c - 在类 UNIX 操作系统上,二进制文件的最少内存使用量是多少?

C - 用指针引用函数进行多次计算

arrays - 检查测试答案

c - 为什么 C 允许隐式函数和无类型变量声明?

c - scanf 在第一个 [C] 后停止工作

c - 在 C 中声明字符串而不给出大小

c - 未知转换类型字符

c - ## 运算符我缺少什么

c - 我的 c 程序打印 "out of memory"-error 但有很多可用的内存空间