Forum: Ruby Question on IO::SEEK_CUR

Be955f2578b8971802ceab589fe24ad3?d=identicon&s=25 Suresh Ilankovan (sureshhey)
on 2016-09-20 16:48
Hey i am abit confuse here. as i want to clarify something on this
IO:SEEK_CUR. For example i have a hoho.txt contains "sure". and i
execute this code.

f = File.new("hoho.txt","r")
while a = f.getc
  puts a.chr
  f.seek(1, IO::SEEK_CUR)
end

The ans prints out:
s
r

isn't 'u' should be printed instead of 'r'? because 1, means after the
character 's', so it will be 'u' isn't it?
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-09-22 08:50
The f.seek moves the read pointer on by 1 position. With other words: It
*skips* the next character.

If you would pass 0 to f.seek instead of 1, you would get the next
character.
Be955f2578b8971802ceab589fe24ad3?d=identicon&s=25 Suresh Ilankovan (sureshhey)
on 2016-09-22 11:56
Ronald Fischer wrote in post #1185057:
> The f.seek moves the read pointer on by 1 position. With other words: It
> *skips* the next character.
>
> If you would pass 0 to f.seek instead of 1, you would get the next
> character.

Thanks a lot :)
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.