Skip to content

Instantly share code, notes, and snippets.

@znz
Created December 25, 2011 12:52
Show Gist options
  • Save znz/1519206 to your computer and use it in GitHub Desktop.
Save znz/1519206 to your computer and use it in GitHub Desktop.
"a+" の挙動確認
#include <stdio.h>
int main() {
FILE *fp = fopen("a-test.txt", "a+");
char buf[4];
printf("%ld\n", ftell(fp));
if (fgets(buf, sizeof(buf), fp))
printf("%s\n", buf);
fputs("test", fp);
printf("%ld\n", ftell(fp));
if (!fgets(buf, sizeof(buf), fp))
printf("fgets failed\n");
fclose(fp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment