的FSEEK並在FSEEK值0L這是什麼值也意味着SEEK_END從最終意味着還幫我EOF CTRL + ž不工作更多的理解與FSEEK()和EOF IN C
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」); ((c = getchar())!= EOF) { putc(c,f1); } 和當我點擊CTRL + Ž我得到 - >箭頭標記和輸入i達到無限循環 也使用 fflush(標準輸入); 它丟失了文件的地址並且抓取了一些垃圾地址,