Reading/Writing a structure into a binary file

谁说胖子不能爱 提交于 2019-11-28 09:31:25

I'm assuming your struct looks like this:

struct Medicazos
{
  char Nombre[60];
  char Clave_Acceso[20];
  char Especialidad[40];
  int Id_Doctor;
  int Estado;
}

You can read/write/copy this guy around as a single unit. There's no need to do piecemeal access until you're ready to actually use the values.

struct Medicazos m = {"Bob", "Password", "Feet", 123, 456};

FILE* f = fopen(...);
fwrite(&m, sizeof(struct Medicazos), 1, f);

And the same (but backward) for fread.

(By the way, your capitalized variable names are killing me.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!