fseekとfseekの値0Lは、この値の意味もseek_endの意味であり、EOF ctrl+zが機能していない場合にも役立ちます。
void modify()
{
int ch1;
FILE *f1;
char c,*word,*sent,fname[20];
printf("Enter the filename to be modified: ");
scanf("%s",fname);
if(searchpath(fname))
{
printf("\n1.Character");
printf("\n2.Word");
printf("\n3.Sentence");
printf("\nEnter U'r choice: ");
scanf("%d",&ch1);
if(ch1==1)
{
f1=fopen(fname,"a+");//use to search the fiel in path variables
fseek(f1, 0L, SEEK_END);
printf("Enter the character and CTRL+Z to exit:\n ");
while((c=getchar())!=EOF)
{
putc(c,f1);
}
}
else if(ch1==2)
{
printf("Enter the word: ");
scanf("%s",word);
f1=fopen(fname,"a+");
fseek(f1, 0L, SEEK_END);
fputs(word,f1);
}
else
{
printf("Enter the sentence and CTRL+Z to exit: ");
f1=fopen(fname,"a+");
fseek(f1, 0L, SEEK_END);
while((c=getchar())!=EOF)
{
putc(c,f1);
}
}
}
else
printf("\nFilename does not exist");
fclose(f1);
}
コードを実行してprintf( "文字を入力し、CTRL + Zで終了します:\ n");を呼び出すと while((c = getchar())!= EOF){putc(c、f1); }そして、ctrl+をクリックすると、 z->矢印マークを付けて入力すると、fflush(stdin);を使用して無限ループに到達します。ファイルのアドレスを失い、ガベージアドレスを取得しました。