By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,952 Members | 1,416 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,952 IT Pros & Developers. It's quick & easy.

structs

P: n/a
hi

i have an assignment on structs. i'am facing some difficulties in that

there is function that requires to read from a binary, i know hw to do
that but another part of it says that it return the number of entries
read from the file. how do we do that.

and another part of it says that we have to add struct details from the
user into an array. i have the code that asks the user for input but
dunno how to add it to a array

hope u can help me

thanz
Deepak

Sep 12 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
07****@gmail.com wrote:
i have an assignment on structs. i'am facing some difficulties in that

there is function that requires to read from a binary, i know hw to do
that but another part of it says that it return the number of entries
read from the file. how do we do that.
Wrap them in a struct. Return that struct.
and another part of it says that we have to add struct details from
the user into an array. i have the code that asks the user for input
but dunno how to add it to a array
Use indexing operator, you know, "[]". If your array has enough room
in it to store the input, use assignment to an element of the array and
then increment the index to prepare to store to the next element.
hope u can help me
Not sure how. You only explained what you know and what you don't know.
Ask a particular question. Put your code on the table, let's see what
you have done so far (since you know enough to have written something).
And read the FAQ. All of it. And I mean *all of it*. You may not be
able to understand some of it, but you need to read it all to see if it
answers some of the questions you have.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 12 '06 #2

P: n/a
<07****@gmail.comwrote:
i have an assignment on structs. i'am facing some difficulties in that

there is function that requires to read from a binary, i know hw to do
that but another part of it says that it return the number of entries
read from the file. how do we do that.
I read your question as:

"... but another part of the assignment says that the function I write
should return the aggregate number of records that the function has read
from the file".

Is that a valid rendition? If so, you may want a static variable in the
fuinction to contain a count of records and update it on each call to the
function. You could add a parameter to the argument list to tell the
function to return the accumulated value, rather than doing it's ordinary
thing.
and another part of it says that we have to add struct details from the
user into an array. i have the code that asks the user for input but
dunno how to add it to a array
We know nothing about this array or this structure. I read it as " I dunno
how to do x with y even though I have z".
Sep 12 '06 #3

P: n/a
07****@gmail.com wrote:
hi

i have an assignment on structs. i'am facing some difficulties in that

there is function that requires to read from a binary, i know hw to do
that but another part of it says that it return the number of entries
read from the file. how do we do that.

and another part of it says that we have to add struct details from the
user into an array. i have the code that asks the user for input but
dunno how to add it to a array

hope u can help me

thanz
Deepak
I suggest that you add "Binary_Read" methods to your structure.

Have code that creates instances, reads them, puts them into a
container, then increments a counter. If the container is smart, you
can query it to find the number of items.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Sep 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.