小编Ser*_*gey的帖子

在C中写入指向文件的指针

我有一个结构:

typedef struct student {
  char *name;
  char *surname;
  int age;
} Student;
Run Code Online (Sandbox Code Playgroud)

我需要将它写入二进制文件.

Student *s = malloc(sizeof(*s));
Run Code Online (Sandbox Code Playgroud)

我用数据填充我的结构,然后我写入文件:

fwrite(s, sizeof(*s), 1, fp);
Run Code Online (Sandbox Code Playgroud)

在我的文件中不存在姓名和姓氏,它有char*的地址.我如何写一个单词,而不是一个地址?

c pointers file

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

c ×1

file ×1

pointers ×1