作者NeilPeng (闲闲没事也会烦)
站内b92902xxx
标题[SP2005] 期中考第七题答案更正
时间Fri May 20 04:27:31 2005
同学你好,
期中考第七题写 101th (100th) 或是 201th (200th) 都可以得到
完整的四分,如果你的答案是 201th (200th) 被扣分的,请带着
你的考卷到 438 室找
彭念劬助教更正。
我下午和晚上一般都会在实验室,周二下课时也会到教室去,如有
不便之处还请见谅。
SP2005 课程助教
彭念劬
答案更正原因如下:
===========================================================
If you write a program like the followings:
fd = fopen("ascii.dat", "r");
fn = fileno(fd);
fgetc(fd);
fseek(fd, 100, SEEK_SET);
lseek(fn, 200, SEEK_SET);
printf("%d\n", fgetc(fd));
You will get the 101th character.
However if you write a program like this:
fd = fopen("ascii.dat", "r");
fn = fileno(fd);
fseek(fd, 100, SEEK_SET);
lseek(fn, 200, SEEK_SET);
printf("%d\n", fgetc(fd));
You will get the 201th character.
This is because the stream buffer of fd is totally empty
before the fseek() is invoked.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.23.113
※ 编辑: NeilPeng 来自: 140.113.23.113 (05/20 04:32)