28 lines
435 B
C
28 lines
435 B
C
// 自定义二进制文件读取
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
typedef struct
|
|
{
|
|
int sid;
|
|
char name[32];
|
|
int age;
|
|
char sex[4];
|
|
} STU;
|
|
|
|
int main()
|
|
{
|
|
FILE *f = fopen("d13.txt", "rb");
|
|
if (NULL == f)
|
|
{
|
|
return 1;
|
|
}
|
|
STU *s = malloc(sizeof(STU));
|
|
fread(s, sizeof(STU), 1, f);
|
|
printf("%d %s %d %s\n", s->sid, s->name, s->age, s->sex);
|
|
free(s);
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
} |