Skip to content

Instantly share code, notes, and snippets.

@7shi 7shi/sparse.cpp
Created Mar 7, 2014

What would you like to do?
#include <stdio.h>
int main() {
// 10バイトのファイルを作成
char a[10] = {0};
FILE *f = fopen("test", "wb");
fwrite(a, 1, sizeof(a), 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));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.