「ftellプロジェクト」の編集履歴(バックアップ)一覧はこちら
「ftellプロジェクト」(2010/07/08 (木) 15:01:26) の最新版変更点
追加された行は緑色になります。
削除された行は赤色になります。
***ftell.c
#highlight(c){{
#include <stdio.h>
int main(void){
FILE *fp = NULL;
char str[100];
long pos;
fp = fopen("test.txt", "a");
if (fp == NULL){
printf("Can't open file!\n");
return -1;
}
printf("Input text:\n");
while(1){
scanf("%s", str);
if (strcmp(str, "end") == 0){
break;
}
else if (strcmp(str, "pos") == 0){
pos = ftell(fp);
printf("(%d)\n", pos);
}
else{
fprintf(fp, "%s", str);
}
}
printf("Input end.\n");
fclose(fp);
return 0;
}
}}