【发布时间】:2011-12-04 20:10:54
【问题描述】:
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"); 而((c=getchar())!=EOF) { putc(c,f1); } 当我点击 ctrl+z 我得到 -> 箭头标记并输入我到达无限循环 也使用 刷新(标准输入); 它丢失了文件的地址并抓取了一些垃圾地址,
【问题讨论】: