运行以下代码时,为什么会在 HALLO 字符串旁边打印额外的垃圾?
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *binfile;
binfile = fopen("binary.bin", "wb+");
char arr[5] = "HALLO";
int integer = 1;
double doub = 1.2345;
fwrite(arr, sizeof(arr), 1, binfile);
fwrite(&integer, sizeof(int), 1, binfile);
fwrite(&doub, sizeof(double), 1, binfile);
fclose(binfile);
binfile = fopen("binary.bin", "r");
char arr2[5];
int integer2;
double doub2;
fread(arr2, sizeof(arr2), 1, binfile);
fread(&integer2, sizeof(int), 1, binfile);
fread(&doub2, sizeof(double), 1, binfile);
printf("%s\n", arr2);
printf("%d\n", integer2);
printf("%lf\n", doub2);
fclose(binfile);
return EXIT_SUCCESS;
}