1
Linuxではこのコードが動作します。ファイルから50000の整数を読み込みます(ファイルサイズ= 200000バイト)。しかし、ビジュアルスタジオ2015 freadは73を返します。 なぜ私はundestandをしないのですか?C. freadはWindowsではなくLinux上で動作します
コンソール:
Oops. Can not read successfully the stack.
size = 50000
rsize = 73
filename = nums
Size of int = 4
Better to STOP
Press any key to continue . . .
コードスニペット:
FILE* f = fopen(fn, "r");
if (f == NULL)
{
printf("\nCan not open file %s\n", fn);
return 1;
}
int* stack = malloc(sizeof(int) * size);
if (stack == NULL)
{
fclose(f);
printf("\nCan not stack the stack - not enough memory\n");
return 2;
}
int rsize = fread(stack, sizeof(int), size, f);
if (size != rsize)
{
printf("\nOops. Can not read successfully the stack.\n size = %d\nrsize = %d\nfilename = %s\nSize of int = %d\nBetter to STOP\n", size, rsize, fn, sizeof(int));
fclose(f);
free(stack);
return 3;
}
ありがとうございます。はい。それは助けになった。 –