473,486 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

File seek

Hi,
I was asked this question in an interview recently. "How do you
move to the 6th byte in a file?" ... My thinking would be to find the
data types in the file, set a base pointer and advance it by 6. I
mean, ptr+6. Another way to ask the same question is how do you move
to the 3rd record in a file (considering that the file is made up of
records).
I told the interviewer that we could do a seek to move to the
specific byte. At that time, the interviewer nodded his head to show
his approval of my answer, but I came to know that he thought there is
a more effective way of doing this. Can anyone throw some pointers on
what that effective way could be?

Regards,
Arvind.
Jul 22 '05 #1
31 9164
Hi,
To move to the 6th byte you dont need to find the data types in the file. A
byte is a byte. Maybe he refered to that.

Mauricio

"Arvind Varma Kalidindi" <ax*****@lycos.com> wrote in message
news:26**************************@posting.google.c om...
Hi,
I was asked this question in an interview recently. "How do you
move to the 6th byte in a file?" ... My thinking would be to find the
data types in the file, set a base pointer and advance it by 6. I
mean, ptr+6. Another way to ask the same question is how do you move
to the 3rd record in a file (considering that the file is made up of
records).
I told the interviewer that we could do a seek to move to the
specific byte. At that time, the interviewer nodded his head to show
his approval of my answer, but I came to know that he thought there is
a more effective way of doing this. Can anyone throw some pointers on
what that effective way could be?

Regards,
Arvind.

Jul 22 '05 #2

On Tue, 10 Aug 2004, Arvind Varma Kalidindi wrote in comp.lang.c:

I was asked this question in an interview recently. "How do you
move to the 6th byte in a file?" ... My thinking would be to find the
data types in the file, set a base pointer and advance it by 6.
This is not coherent English. Files don't have "data types," and
you can't set C or C++ pointers to point /into/ files. You have to
read out the data first.
I mean, ptr+6. Another way to ask the same question is how do you move
to the 3rd record in a file (considering that the file is made up of
records).
And assuming that the first two records in the file have a total of
6 bytes between them, yes. :)
I told the interviewer that we could do a seek to move to the
specific byte. At that time, the interviewer nodded his head to show
his approval of my answer, but I came to know that he thought there is
a more effective way of doing this. Can anyone throw some pointers on
what that effective way could be?


I doubt he thought there was a more /effective/ way. You could
have been more /detailed/ in your answer, though; he might have
expected an interview candidate in C to be able to write down

fseek(fp, 6, SEEK_SET);

from memory (although I personally have to look up the order of
those parameters every time), and perhaps to explain why

if (fseek(fp, 6, SEEK_SET)) {
puts("I/O error during fseek");
}

would be more appropriate. He might have expected you to
recall that 'fseek' does not have well-defined behavior on text
streams except in very specific circumstances---consider the
definition of "the 6th byte" with respect to the text file

apple
banana
EOF

Is "the 6th byte" an ASCII newline, a carriage return, the letter 'b',
or what? A complete answer must at least explain the problem; and
the interviewer might then follow up with, "What is the best
interpretation in your opinion, and how would you implement it?"
leading to

for (i=0; i < 6; ++i) getc(fp);

The interviewer might even have wondered if you'd realize that
'fseek(fp, 6, SEEK_SET)' does /not/ retrieve the sixth byte in
a binary file at all, but rather the /seventh/ byte, because
'fseek' counts from zero. (It took me a while, too.)

And of course there are a whole slew of other answers in C++.
Don't crosspost between groups for different languages like this;
it just confuses people, and half the answers you get will be
unusable.

-Arthur

Jul 22 '05 #3
ax*****@lycos.com (Arvind Varma Kalidindi) wrote:
# Hi,
# I was asked this question in an interview recently. "How do you
# move to the 6th byte in a file?" ... My thinking would be to find the
# data types in the file, set a base pointer and advance it by 6. I
# mean, ptr+6. Another way to ask the same question is how do you move
# to the 3rd record in a file (considering that the file is made up of
# records).

Something here is garbled or missing. There are many different ways of
encoding records in a file, and of indexing (or not indexing) a file's
record. Without information about file and record formats and indexing,
there's no real answer.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
A bunch of savages in this town.
Jul 22 '05 #4


SM Ryan wrote:
ax*****@lycos.com (Arvind Varma Kalidindi) wrote:
# Hi,
# I was asked this question in an interview recently. "How do you
# move to the 6th byte in a file?" ... My thinking would be to find the
# data types in the file, set a base pointer and advance it by 6. I
# mean, ptr+6. Another way to ask the same question is how do you move
# to the 3rd record in a file (considering that the file is made up of
# records).

Something here is garbled or missing. There are many different ways of
encoding records in a file, and of indexing (or not indexing) a file's
record. Without information about file and record formats and indexing,
there's no real answer.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
A bunch of savages in this town.


No, at the C source-code level, all files are just an un-differentiated
list of bytes. If the OS stores files as files of fixed record types
(such as VAX/VMS), then it is up to the implementation to "hide" these
messy details from the programmer.

--
Ron Collins
Air Defense/RTSC/BCS
"I have a plan so cunning, you could put a tail on it and call it a weasel"

Jul 22 '05 #5
SM Ryan wrote:
ax*****@lycos.com (Arvind Varma Kalidindi) wrote:

# I was asked this question in an interview recently. "How do you
# find the move to the 6th byte in a file?" ... My thinking would
# be to data types in the file, set a base pointer and advance it
# by 6. I mean, ptr+6. Another way to ask the same question is how
# do you move to the 3rd record in a file (considering that the
# file is made up of records).

Something here is garbled or missing. There are many different
ways of encoding records in a file, and of indexing (or not
indexing) a file's record. Without information about file and
record formats and indexing, there's no real answer.


Please don't use a non-standard quote marker (your #). It fouls
up reformatting software.

Answering the first sentence in the OPs article: Just read the
first 6 bytes of the newly opened stream with fread(). Discard
them. You are positioned.

--
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
"A man who is right every time is not likely to do very much."
- Francis Crick, co-discover of DNA
Jul 22 '05 #6
RCollins <rc***@nospam.theriver.com> writes:
[...]
No, at the C source-code level, all files are just an un-differentiated
list of bytes. If the OS stores files as files of fixed record types
(such as VAX/VMS), then it is up to the implementation to "hide" these
messy details from the programmer.


For purposes of C stdio, yes. In addition, the OS can (and does)
provide system-specific interfaces that expose all the fixd record
stuff to the programmer.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 22 '05 #7
Keith Thompson <ks***@mib.org> wrote:
# RCollins <rc***@nospam.theriver.com> writes:
# [...]
# > No, at the C source-code level, all files are just an un-differentiated
# > list of bytes. If the OS stores files as files of fixed record types
# > (such as VAX/VMS), then it is up to the implementation to "hide" these
# > messy details from the programmer.
#
# For purposes of C stdio, yes. In addition, the OS can (and does)
# provide system-specific interfaces that expose all the fixd record
# stuff to the programmer.

I didn't realise fgetpos and ftell had been redefined so they no longer
can return a cookie that is system dependent, but now always return a
byte offset. I bet that really cheesed off the VMS people.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Raining down sulphur is like an endurance trial, man. Genocide is the
most exhausting activity one can engage in. Next to soccer.
Jul 22 '05 #8


Keith Thompson wrote:
RCollins <rc***@nospam.theriver.com> writes:
[...]
No, at the C source-code level, all files are just an un-differentiated
list of bytes. If the OS stores files as files of fixed record types
(such as VAX/VMS), then it is up to the implementation to "hide" these
messy details from the programmer.

For purposes of C stdio, yes. In addition, the OS can (and does)
provide system-specific interfaces that expose all the fixd record

^^^^^^^^^^^^^^^^^^^^^^^^^^ stuff to the programmer.


Non-standard stuff. Do we care about that in c.l.c. ?

--
Ron Collins
Air Defense/RTSC/BCS
"I have a plan so cunning, you could put a tail on it and call it a weasel"

Jul 22 '05 #9


SM Ryan wrote:
Keith Thompson <ks***@mib.org> wrote:
# RCollins <rc***@nospam.theriver.com> writes:
# [...]
# > No, at the C source-code level, all files are just an un-differentiated
# > list of bytes. If the OS stores files as files of fixed record types
# > (such as VAX/VMS), then it is up to the implementation to "hide" these
# > messy details from the programmer.
#
# For purposes of C stdio, yes. In addition, the OS can (and does)
# provide system-specific interfaces that expose all the fixd record
# stuff to the programmer.

I didn't realise fgetpos and ftell had been redefined so they no longer
can return a cookie that is system dependent, but now always return a
byte offset. I bet that really cheesed off the VMS people.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Raining down sulphur is like an endurance trial, man. Genocide is the
most exhausting activity one can engage in. Next to soccer.


Actually, it really made life easier (at least, in my group). VMS
provides about a ga-zillion different record formats, and we were
writing specific code for each format (when using FORTRAN). With the
more simplistic <stdio> stuff, all we had to do was parse our data
from a single input format.

--
Ron Collins
Air Defense/RTSC/BCS
"I have a plan so cunning, you could put a tail on it and call it a weasel"

Jul 22 '05 #10
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
Keith Thompson <ks***@mib.org> wrote:
# RCollins <rc***@nospam.theriver.com> writes:
# [...]
# > No, at the C source-code level, all files are just an un-differentiated
# > list of bytes. If the OS stores files as files of fixed record types
# > (such as VAX/VMS), then it is up to the implementation to "hide" these
# > messy details from the programmer.
#
# For purposes of C stdio, yes. In addition, the OS can (and does)
# provide system-specific interfaces that expose all the fixd record
# stuff to the programmer.

I didn't realise fgetpos and ftell had been redefined so they no longer
can return a cookie that is system dependent, but now always return a
byte offset. I bet that really cheesed off the VMS people.


The fpos_t value used by fgetpos and ftell may contain arbitrary
system-specific information, but as far as I know it can't be used to
get at VMS's record-oriented file interface.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 22 '05 #11
RCollins <rc***@nospam.theriver.com> writes:
Keith Thompson wrote:
RCollins <rc***@nospam.theriver.com> writes:
[...]
No, at the C source-code level, all files are just an un-differentiated
list of bytes. If the OS stores files as files of fixed record types
(such as VAX/VMS), then it is up to the implementation to "hide" these
messy details from the programmer.

For purposes of C stdio, yes. In addition, the OS can (and does)
provide system-specific interfaces that expose all the fixd record

^^^^^^^^^^^^^^^^^^^^^^^^^^
stuff to the programmer.


Non-standard stuff. Do we care about that in c.l.c. ?


Not about the details, but there's nothing off-topic about mentioning
that system-specific interfaces exist.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 22 '05 #12
Keith Thompson <ks***@mib.org> wrote:
# SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
# > Keith Thompson <ks***@mib.org> wrote:
# > # RCollins <rc***@nospam.theriver.com> writes:
# > # [...]
# > # > No, at the C source-code level, all files are just an un-differentiated
# > # > list of bytes. If the OS stores files as files of fixed record types
# > # > (such as VAX/VMS), then it is up to the implementation to "hide" these
# > # > messy details from the programmer.
# > #
# > # For purposes of C stdio, yes. In addition, the OS can (and does)
# > # provide system-specific interfaces that expose all the fixd record
# > # stuff to the programmer.
# >
# > I didn't realise fgetpos and ftell had been redefined so they no longer
# > can return a cookie that is system dependent, but now always return a
# > byte offset. I bet that really cheesed off the VMS people.
#
# The fpos_t value used by fgetpos and ftell may contain arbitrary
# system-specific information, but as far as I know it can't be used to
# get at VMS's record-oriented file interface.

Why don't you and RCollins get together and come up with a consistent
answer.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
A bunch of savages in this town.
Jul 22 '05 #13
On Wed, 11 Aug 2004 21:56:27 -0000, in comp.lang.c , SM Ryan
<wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> wrote:
Keith Thompson <ks***@mib.org> wrote:
# SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
# >
# > I didn't realise fgetpos and ftell had been redefined so they no longer
# > can return a cookie that is system dependent, but now always return a
# > byte offset. I bet that really cheesed off the VMS people.
#
# The fpos_t value used by fgetpos and ftell may contain arbitrary
# system-specific information, but as far as I know it can't be used to
# get at VMS's record-oriented file interface.

Why don't you and RCollins get together and come up with a consistent
answer.


In fact the answers /were/ consistent, if you read them carefully.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 22 '05 #14
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
Keith Thompson <ks***@mib.org> wrote:
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
Keith Thompson <ks***@mib.org> wrote:
> RCollins <rc***@nospam.theriver.com> writes:
> [...]
> > No, at the C source-code level, all files are just an
> > un-differentiated list of bytes. If the OS stores files as
> > files of fixed record types (such as VAX/VMS), then it is
> > up to the implementation to "hide" these messy details from
> > the programmer.
> For purposes of C stdio, yes. In addition, the OS can (and does)
> provide system-specific interfaces that expose all the fixd record
> stuff to the programmer.

I didn't realise fgetpos and ftell had been redefined so they no
longer can return a cookie that is system dependent, but now always
return a byte offset. I bet that really cheesed off the VMS people.


The fpos_t value used by fgetpos and ftell may contain arbitrary
system-specific information, but as far as I know it can't be used to
get at VMS's record-oriented file interface.


Why don't you and RCollins get together and come up with a consistent
answer.


How were our answers inconsistent?

BTW, a couple of requests: First, please use '>', not '#', to denote
quoted text; using '#' confuses reformatters. Second, your signature
should be introduced by a line consisting of "-- "; yours is missing
the trailing blank, so it isn't being recognized as a signature.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 22 '05 #15


SM Ryan wrote:
Keith Thompson <ks***@mib.org> wrote:
# SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
# > Keith Thompson <ks***@mib.org> wrote:
# > # RCollins <rc***@nospam.theriver.com> writes:
# > # [...]
# > # > No, at the C source-code level, all files are just an un-differentiated
# > # > list of bytes. If the OS stores files as files of fixed record types
# > # > (such as VAX/VMS), then it is up to the implementation to "hide" these
# > # > messy details from the programmer.
# > #
# > # For purposes of C stdio, yes. In addition, the OS can (and does)
# > # provide system-specific interfaces that expose all the fixd record
# > # stuff to the programmer.
# >
# > I didn't realise fgetpos and ftell had been redefined so they no longer
# > can return a cookie that is system dependent, but now always return a
# > byte offset. I bet that really cheesed off the VMS people.
#
# The fpos_t value used by fgetpos and ftell may contain arbitrary
# system-specific information, but as far as I know it can't be used to
# get at VMS's record-oriented file interface.

Why don't you and RCollins get together and come up with a consistent
answer.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
A bunch of savages in this town.


<OT rambling about VAX/VMS>
What was inconsistent? The C compiler hides the (very) ugly details
of the VAX/VMS record system. Thank (deity of your choice) for that!
</OT>

--
Ron Collins
Air Defense/RTSC/BCS
"I have a plan so cunning, you could put a tail on it and call it a weasel"

Jul 22 '05 #16
RCollins <rc***@nospam.theriver.com> wrote:
#
#
# SM Ryan wrote:
#
# > Keith Thompson <ks***@mib.org> wrote:
# > # SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
# > # > Keith Thompson <ks***@mib.org> wrote:
# > # > # RCollins <rc***@nospam.theriver.com> writes:
# > # > # [...]
# > # > # > No, at the C source-code level, all files are just an un-differentiated
# > # > # > list of bytes. If the OS stores files as files of fixed record types
# > # > # > (such as VAX/VMS), then it is up to the implementation to "hide" these
# > # > # > messy details from the programmer.
# > # > #
# > # > # For purposes of C stdio, yes. In addition, the OS can (and does)
# > # > # provide system-specific interfaces that expose all the fixd record
# > # > # stuff to the programmer.
# > # >
# > # > I didn't realise fgetpos and ftell had been redefined so they no longer
# > # > can return a cookie that is system dependent, but now always return a
# > # > byte offset. I bet that really cheesed off the VMS people.
# > #
# > # The fpos_t value used by fgetpos and ftell may contain arbitrary
# > # system-specific information, but as far as I know it can't be used to
# > # get at VMS's record-oriented file interface.
# >
# > Why don't you and RCollins get together and come up with a consistent
# > answer.
# >
# > --
# > SM Ryan http://www.rawbw.com/~wyrmwif/
# > A bunch of savages in this town.
#
# <OT rambling about VAX/VMS>
# What was inconsistent? The C compiler hides the (very) ugly details
# of the VAX/VMS record system. Thank (deity of your choice) for that!
# </OT>

So are you saying fgetpos and ftell always return a byte offset into the
file and never a system dependent cookie? Keith doesn't agree with you.
Who am I to believe?

--
SM Ryan http://www.rawbw.com/~wyrmwif/
GERBILS
GERBILS
GERBILS
Jul 22 '05 #17
SM Ryan wrote:
RCollins <rc***@nospam.theriver.com> wrote:
# .... snip ... #
# <OT rambling about VAX/VMS>
# What was inconsistent? The C compiler hides the (very) ugly
# details of the VAX/VMS record system. Thank (deity of your
# choice) for that! </OT>

So are you saying fgetpos and ftell always return a byte offset
into the file and never a system dependent cookie? Keith doesn't
agree with you. Who am I to believe?


The people who ask you to cease and desist with the non-standard
quotation marker.

--
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
"A man who is right every time is not likely to do very much."
- Francis Crick, co-discover of DNA

Jul 22 '05 #18


SM Ryan wrote:
RCollins <rc***@nospam.theriver.com> wrote:
#
#
# SM Ryan wrote:
#
# > Keith Thompson <ks***@mib.org> wrote:
# > # SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
# > # > Keith Thompson <ks***@mib.org> wrote:
# > # > # RCollins <rc***@nospam.theriver.com> writes:
# > # > # [...]
# > # > # > No, at the C source-code level, all files are just an un-differentiated
# > # > # > list of bytes. If the OS stores files as files of fixed record types
# > # > # > (such as VAX/VMS), then it is up to the implementation to "hide" these
# > # > # > messy details from the programmer.
# > # > #
# > # > # For purposes of C stdio, yes. In addition, the OS can (and does)
# > # > # provide system-specific interfaces that expose all the fixd record
# > # > # stuff to the programmer.
# > # >
# > # > I didn't realise fgetpos and ftell had been redefined so they no longer
# > # > can return a cookie that is system dependent, but now always return a
# > # > byte offset. I bet that really cheesed off the VMS people.
# > #
# > # The fpos_t value used by fgetpos and ftell may contain arbitrary
# > # system-specific information, but as far as I know it can't be used to
# > # get at VMS's record-oriented file interface.
# >
# > Why don't you and RCollins get together and come up with a consistent
# > answer.
# >
# > --
# > SM Ryan http://www.rawbw.com/~wyrmwif/
# > A bunch of savages in this town.
#
# <OT rambling about VAX/VMS>
# What was inconsistent? The C compiler hides the (very) ugly details
# of the VAX/VMS record system. Thank (deity of your choice) for that!
# </OT>

So are you saying fgetpos and ftell always return a byte offset into the
file and never a system dependent cookie? Keith doesn't agree with you.
Who am I to believe?

--
SM Ryan http://www.rawbw.com/~wyrmwif/
GERBILS
GERBILS
GERBILS


I haven't the foggiest idea what fgetpos returns in it's value.
I don't care. I get a file position from fgetpos, and later I pass that
value back to fsetpos to get back to the same place in the file. If
there is system dependant data in there, then the compiler successfully
hid it from me.

Note that this is true on *any* system, not just VAX/VMS. In fact, I
would assume that the 'value' returned by the fgetpos family of
functions is completely different on each OS type.

From the C89 standard (the only one I have handy at the moment):

<Q>
4.9.9.1 The fgetpos function

Synopsis

#include <stdio.h>
int fgetpos(FILE *stream, fpos_t *pos);

Description

The fgetpos function stores the current value of the file position
indicator for the stream pointed to by stream in the object pointed to
by pos . The value stored contains unspecified information usable by
^^^^^^^^^^^^^^^^^^^^^^^
the fsetpos function for repositioning the stream to its position at
the time of the call to the fgetpos function.
</Q>

Note the part I underlined. Also note, I *still* don't see the
inconsistancy you are talking about.

--
Ron Collins
Air Defense/RTSC/BCS
"I have a plan so cunning, you could put a tail on it and call it a weasel"

Jul 22 '05 #19
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
RCollins <rc***@nospam.theriver.com> wrote: [...] # <OT rambling about VAX/VMS>
# What was inconsistent? The C compiler hides the (very) ugly details
# of the VAX/VMS record system. Thank (deity of your choice) for that!
# </OT>

So are you saying fgetpos and ftell always return a byte offset into the
file and never a system dependent cookie? Keith doesn't agree with you.
Who am I to believe?


Actually, I think RCollins are in complete agreement that you're
wrong.

RCollins said that the C compiler (and by implication fgetpos and
ftell) hides the details of the VAX/VMS record system. (Strictly
speaking it's the library, not the compiler, but that's a minor
point.) He said nothing about *how* it hides those details. fpos_t
is a system dependent cookie; one way to implement such a cookie is as
a byte offset.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 22 '05 #20
RCollins <rc***@nospam.theriver.com> wrote:
#
#
# SM Ryan wrote:
#
# > RCollins <rc***@nospam.theriver.com> wrote:
# > #
# > #
# > # SM Ryan wrote:
# > #
# > # > Keith Thompson <ks***@mib.org> wrote:
# > # > # SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
# > # > # > Keith Thompson <ks***@mib.org> wrote:
# > # > # > # RCollins <rc***@nospam.theriver.com> writes:
# > # > # > # [...]
# > # > # > # > No, at the C source-code level, all files are just an un-differentiated
# > # > # > # > list of bytes. If the OS stores files as files of fixed record types
# > # > # > # > (such as VAX/VMS), then it is up to the implementation to "hide" these
# > # > # > # > messy details from the programmer.
# > # > # > #
# > # > # > # For purposes of C stdio, yes. In addition, the OS can (and does)
# > # > # > # provide system-specific interfaces that expose all the fixd record
# > # > # > # stuff to the programmer.
# > # > # >
# > # > # > I didn't realise fgetpos and ftell had been redefined so they no longer
# > # > # > can return a cookie that is system dependent, but now always return a
# > # > # > byte offset. I bet that really cheesed off the VMS people.
# > # > #
# > # > # The fpos_t value used by fgetpos and ftell may contain arbitrary
# > # > # system-specific information, but as far as I know it can't be used to
# > # > # get at VMS's record-oriented file interface.
# > # >
# > # > Why don't you and RCollins get together and come up with a consistent
# > # > answer.
# > # >
# > # > --
# > # > SM Ryan http://www.rawbw.com/~wyrmwif/
# > # > A bunch of savages in this town.
# > #
# > # <OT rambling about VAX/VMS>
# > # What was inconsistent? The C compiler hides the (very) ugly details
# > # of the VAX/VMS record system. Thank (deity of your choice) for that!
# > # </OT>
# >
# > So are you saying fgetpos and ftell always return a byte offset into the
# > file and never a system dependent cookie? Keith doesn't agree with you.
# > Who am I to believe?

# I haven't the foggiest idea what fgetpos returns in it's value.
# I don't care. I get a file position from fgetpos, and later I pass that
# value back to fsetpos to get back to the same place in the file. If
# there is system dependant data in there, then the compiler successfully
# hid it from me.

Okay. So the weird thing to me is that I started off saying that you can't
just fseek some byte offset on any operating system, but that what
you specify in fseek depends on the system, file organisation, etc. But
someone else pops and says, no, at the C source-code level, all files are
just an un-differentiated list of bytes. So are you saying I was correct
originally and the guy who popped off was just being a jackass. Or what?

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Haven't you ever heard the customer is always right?
Jul 22 '05 #21
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
RCollins <rc***@nospam.theriver.com> wrote: [...] # I haven't the foggiest idea what fgetpos returns in it's value.
# I don't care. I get a file position from fgetpos, and later I pass that
# value back to fsetpos to get back to the same place in the file. If
# there is system dependant data in there, then the compiler successfully
# hid it from me.

Okay. So the weird thing to me is that I started off saying that you can't
just fseek some byte offset on any operating system, but that what
you specify in fseek depends on the system, file organisation, etc. But
someone else pops and says, no, at the C source-code level, all files are
just an un-differentiated list of bytes. So are you saying I was correct
originally and the guy who popped off was just being a jackass. Or what?


I've directed followups to comp.lang.c; this isn't particularly
relevant to C++.

Please stop using '#' to delimit quotations, and start using "-- "
(the trailing blank is mandatory) to delimit your signature.

Nobody other than you is being a jackass. That was carefully phrased,
and is not intended to imply that you're a jackass yourself, merely to
refute your implication that somebody else (I'm not sure who) is being
a jackass.

Did you intend to change the subject from fgetpos/fsetpos to
ftell/fseek?

ftell and fseek use long int values to represent file positions. For
binary files, these values indicate byte offsets. For text files, it
may not be so simple; the only values you can safely pass to fseek are
zero and values previously returned by ftell for the same stream.

fgetpos and fsetpos use fpos_t values to represent a combination of a
file position and a parse state. The internal representation of an
fpos_t value is not defined by the language; it may or may not include
a simple byte offset. It just has to be implemented in such a way
that an fpos_t value returned by fgetpos can be used in a subsequent
call to fsetpos.

Any record structure implemented by the operating system may or may
not be reflected in the represention of fpos_t, but it can't be used
by any portable C program.

See any decent C text book, or the standard, for more information.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 22 '05 #22
On Thu, 12 Aug 2004 07:24:30 -0000
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> wrote:
RCollins <rc***@nospam.theriver.com> wrote:
#
#
# SM Ryan wrote:
#
# > RCollins <rc***@nospam.theriver.com> wrote:
<snip>
# > # <OT rambling about VAX/VMS>
# > # What was inconsistent? The C compiler hides the (very) ugly
# > # details of the VAX/VMS record system. Thank (deity of your
# > # choice) for that!</OT>
# >
# > So are you saying fgetpos and ftell always return a byte offset
# > into the file and never a system dependent cookie? Keith doesn't
# > agree with you. Who am I to believe?

# I haven't the foggiest idea what fgetpos returns in it's value.
# I don't care. I get a file position from fgetpos, and later I pass
# that value back to fsetpos to get back to the same place in the
# file. If there is system dependant data in there, then the compiler
# successfully hid it from me.

Okay. So the weird thing to me is that I started off saying that you
can't just fseek some byte offset on any operating system, but that
what you specify in fseek depends on the system, file organisation,
etc. But someone else pops and says, no, at the C source-code level,
all files are just an un-differentiated list of bytes. So are you
saying I was correct originally and the guy who popped off was just
being a jackass. Or what?


Nothing that you are allowed to know about makes it look like anything
other than a stream of bytes. The fact that you are not allowed to look
at the value returned by fgetpos means that you can't tell that it might
be record number + offset or something even stranger. It is hidden
because you are not told what it is and you are not allowed to do
anything with the value apart from pass it to fsetpos.

fseek, on the other hand, takes an offset in bytes which you do play
with yourself and and strangeness of the file system is again hidden
from you.
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
Jul 22 '05 #23


SM Ryan wrote:
RCollins <rc***@nospam.theriver.com> wrote:
#
#
# SM Ryan wrote:
#
# > RCollins <rc***@nospam.theriver.com> wrote:
# > #
# > #
# > # SM Ryan wrote: <snip>

Okay. So the weird thing to me is that I started off saying that you can't
just fseek some byte offset on any operating system, but that what
you specify in fseek depends on the system, file organisation, etc. But
someone else pops and says, no, at the C source-code level, all files are
just an un-differentiated list of bytes. So are you saying I was correct
originally and the guy who popped off was just being a jackass. Or what?

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Haven't you ever heard the customer is always right?


I think Keith and Flash summed it up pretty nicely. Use ftell/fseek
if you want to use a byte offset into a file; use fgetpos/fsetpos if
you just want to remember a specific location in a file.

As for the jackass part ... I don't remember exactly who it was, but
it might of been me. I *am* sometimes a jackass -- but not
intentionally. Honestly, I don't see why some people (ex-wives in
particular) take offsense just because somebody calls them a
bone-headed slack-jawed idiot :)

--
Ron Collins
Air Defense/RTSC/BCS
"I have a plan so cunning, you could put a tail on it and call it a weasel"

Jul 22 '05 #24
Flash Gordon <sp**@flash-gordon.me.uk> wrote"
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> wrote:
RCollins <rc***@nospam.theriver.com> wrote:
#
#
# SM Ryan wrote:
#
# > # <OT rambling about VAX/VMS>
# > # What was inconsistent? The C compiler hides the (very) ugly
# > # details of the VAX/VMS record system. Thank (deity of your
# > # choice) for that!</OT>
# >
# > So are you saying fgetpos and ftell always return a byte offset
# > into the file and never a system dependent cookie? Keith doesn't
# > agree with you. Who am I to believe?


fseek, on the other hand, takes an offset in bytes which you do play
with yourself and and strangeness of the file system is again hidden
from you.


Excellent thinly-veiled insult :) Perhaps he uses his non-standard
quote marker as an aide.
Jul 22 '05 #25
On 12 Aug 2004 14:23:19 -0700
ol*****@inspire.net.nz (Old Wolf) wrote:
Flash Gordon <sp**@flash-gordon.me.uk> wrote"
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> wrote:
RCollins <rc***@nospam.theriver.com> wrote:
#
#
# SM Ryan wrote:
#
# > # <OT rambling about VAX/VMS>
# > # What was inconsistent? The C compiler hides the (very) ugly
# > # details of the VAX/VMS record system. Thank (deity of your
# > # choice) for that!</OT>
# >
# > So are you saying fgetpos and ftell always return a byte
offset# > into the file and never a system dependent cookie? Keith
doesn't# > agree with you. Who am I to believe?
fseek, on the other hand, takes an offset in bytes which you do play
with yourself and and strangeness of the file system is again hidden
from you.


Excellent thinly-veiled insult :)


Entirely unintended. :-)
Perhaps he uses his non-standard
quote marker as an aide.


Yes, I agree that # as a quote marker is a real pain on a C news group.
If I set it as a quote marker it would make reading C source code
harder. If I don't it screws up the automatic wrapping etc.
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
Jul 22 '05 #26
Flash Gordon <sp**@flash-gordon.me.uk> wrote:

# Nothing that you are allowed to know about makes it look like anything
# other than a stream of bytes. The fact that you are not allowed to look

Actually, nothing that you are allowed to know about makes it looks like
anything at all except what you extract from the stream based on the
return of functions. Anything else is implementation dependent. And
off topic.

# fseek, on the other hand, takes an offset in bytes which you do play
# with yourself and and strangeness of the file system is again hidden
# from you.

See this is kind of thing that confuses me. I have experts like you
tell me this, but then I read things like

[#4] For a text stream, either offset shall be zero, or
offset shall be a value returned by an earlier successful
call to the ftell function on a stream associated with the
same file and whence shall be SEEK_SET.

So was I wrong to say that this things are implementation dependent
or am I just dealing with another jackass?

--
SM Ryan http://www.rawbw.com/~wyrmwif/
JUSTICE!
Justice is dead.
Jul 22 '05 #27
On Fri, 13 Aug 2004 03:14:15 -0000
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> wrote:
Flash Gordon <sp**@flash-gordon.me.uk> wrote:

# Nothing that you are allowed to know about makes it look like
# anything other than a stream of bytes. The fact that you are not
# allowed to look

Actually, nothing that you are allowed to know about makes it looks
like anything at all except what you extract from the stream based on
the return of functions. Anything else is implementation dependent.
And off topic.
I failed to allow for text files. Since I have never claimed to be
perfect I am allowed to make mistakes or overlook things.

In this instance I will defer to Kieth on the values you can pass to
fseek when using a text file. However, the storage method of lines be it
CR/LF, LF/CR, CR, LF, variable record sizes, 0 padded fixed length
records or something stranger is still hidden from the C coder unless
they break the rules of C. Reading the text file as a text file byte by
byte you will see it as a stream of bytes with a single byte indicating
a new line whatever storage method is used.
# fseek, on the other hand, takes an offset in bytes which you do play
# with yourself and and strangeness of the file system is again hidden
# from you.

See this is kind of thing that confuses me. I have experts like you
tell me this, but then I read things like

[#4] For a text stream, either offset shall be zero, or
offset shall be a value returned by an earlier successful
call to the ftell function on a stream associated with the
same file and whence shall be SEEK_SET.

So was I wrong to say that this things are implementation dependent
or am I just dealing with another jackass?


If you pass something other than one of the allowed values to fseek on a
text stream then you are leaving the realms of C. If you stick to the
allowed methods of accessing files then all the implementation dependant
detail is hidden from you.
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
Jul 22 '05 #28
On Fri, 13 Aug 2004 03:14:15 -0000, in comp.lang.c , SM Ryan
<wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> wrote:
So was I wrong to say that this things are implementation dependent
or am I just dealing with another jackass?


Ok, thats one Jackass too many. You're a rude idiot, and are herewith
plonked.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 22 '05 #29
# I failed to allow for text files. Since I have never claimed to be
# perfect I am allowed to make mistakes or overlook things.

Perhaps you should avoid condenscending and snide remarks when
responding to someone who did allow for text files.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
I have no respect for people with no shopping agenda.
Jul 22 '05 #30
SM Ryan <wy*****@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
# I failed to allow for text files. Since I have never claimed to be
# perfect I am allowed to make mistakes or overlook things.

Perhaps you should avoid condenscending and snide remarks when
responding to someone who did allow for text files.


Perhaps you should avoid condenscending and snide remarks altogether.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 22 '05 #31
SM Ryan wrote:

# I failed to allow for text files. Since I have never claimed to
# be perfect I am allowed to make mistakes or overlook things.

Perhaps you should avoid condenscending and snide remarks when
responding to someone who did allow for text files.


PLONK for refusal to cooperate with existing standards or even to
present any excuse. I suggest others do likewise.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Jul 22 '05 #32

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4915
by: Grumfish | last post by:
Is there a way to see the next character of an input file object without advancing the position in the file?
5
10123
by: simon place | last post by:
is the code below meant to produce rubbish?, i had expected an exception. f=file('readme.txt','w') f.write(' ') f.read() ( PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) on win32. ) I got...
3
4582
by: Pernell Williams | last post by:
Hi all: I am new to Python, and this is my first post (and it won't be my last!), so HELLO EVERYONE!! I am attempting to use "xreadlines", an outer loop and an inner loop in conjunction with...
6
43961
by: Neil Patel | last post by:
I have a log file that puts the most recent record at the bottom of the file. Each line is delimited by a \r\n Does anyone know how to seek to the end of the file and start reading backwards?
0
3907
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
2
2150
by: DAVE P | last post by:
below is code snippet what im trying to do is open a file and Read Bytes into a buffer find end of line (like crlf) in this case "~" The buffer will be the bytes up to the "~" then i need to...
19
5349
by: Lee Crabtree | last post by:
Is there a class in the framework that allows me read text from a file in an unbuffered manner? That is, I'd like to be able to read lines in the same manner as StreamReader.ReadLine(), but I also...
4
2107
by: MikeJ | last post by:
make a While loop ofs = TextFileServer("somefile") string srow while (ofs=false) { srow=ofs.getRow(); Console.Writeline(srow); }
2
2672
by: tgiles | last post by:
Hi, All! I started back programming Python again after a hiatus of several years and run into a sticky problem that I can't seem to fix, regardless of how hard I try- it it starts with tailing a...
6
18286
by: globalrev | last post by:
i ahve a program that takes certain textsnippets out of one file and inserts them into another. problem is it jsut overwrites the first riow every time. i want to insert every new piece of...
0
7099
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4864
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3069
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.