BUPT-homework/semester2/pset3/2-write.c

72 lines
1.5 KiB
C
Raw Permalink Normal View History

2022-04-03 23:22:03 +08:00
#include <stdio.h>
int main(void) {
FILE *fp = fopen("dict.dic", "rb");
char a,
aa[5]; //注意这里数组aa为正常使用的字符串所以会包含字符'\0',它不需要输出
short b, bb[5];
int c, cc[5];
long d, dd[5];
long long e, ee[5];
float g, gg[5];
double h, hh[5];
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
fread(&a, sizeof(a), 1, fp);
fread(&b, sizeof(b), 1, fp);
fread(&c, sizeof(c), 1, fp);
fread(&d, sizeof(d), 1, fp);
fread(&e, sizeof(e), 1, fp);
fread(&g, sizeof(g), 1, fp);
fread(&h, sizeof(h), 1, fp);
fread(aa, sizeof(a), 5, fp);
fread(bb, sizeof(b), 5, fp);
fread(cc, sizeof(c), 5, fp);
fread(dd, sizeof(d), 5, fp);
fread(ee, sizeof(e), 5, fp);
fread(gg, sizeof(g), 5, fp);
fread(hh, sizeof(h), 5, fp);
}
printf("%c\n", a);
printf("%i\n", b);
printf("%d\n", c);
printf("%ld\n", d);
printf("%lld\n", e);
printf("%f\n", g);
printf("%lf\n", h);
printf("%s\n", aa);
for (int i = 0; i < 4; i++) {
printf("%i ", bb[i]);
}
printf("%i\n", bb[4]);
for (int i = 0; i < 4; i++) {
printf("%i ", cc[i]);
}
printf("%i\n", cc[4]);
for (int i = 0; i < 4; i++) {
printf("%li ", dd[i]);
}
printf("%li\n", dd[4]);
for (int i = 0; i < 4; i++) {
printf("%lli ", ee[i]);
}
printf("%lli\n", ee[4]);
for (int i = 0; i < 4; i++) {
printf("%f ", gg[i]);
}
printf("%f\n", gg[4]);
for (int i = 0; i < 4; i++) {
printf("%lf ", hh[i]);
}
printf("%lf\n", hh[4]);
fclose(fp);
return 0;
}