Created
March 7, 2014 12:28
-
-
Save 7shi/9410583 to your computer and use it in GitHub Desktop.
[C++]スパースファイルの実験
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
// 10バイトのファイルを作成 | |
char a[10] = {0}; | |
FILE *f = fopen("test", "wb"); | |
fwrite(a, 1, sizeof(a), f); | |
fclose(f); | |
f = fopen("test", "r+b"); | |
// 100バイト目にシーク(範囲外だがOK) | |
fseek(f, 100, SEEK_SET); | |
// 読み込み(失敗) | |
printf("%d\n", fread(a, 1, sizeof(a), f)); | |
// 書き込み(成功) → ファイルサイズが110バイトになる | |
printf("%d\n", fwrite(a, 1, sizeof(a), f)); | |
fclose(f); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment