473,946 Members | 8,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

structs

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
3 2080
07****@gmail.co m 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
<07****@gmail.c omwrote:
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
07****@gmail.co m 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_Rea d" 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.l earn.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2031
by: news.microsoft.com | last post by:
Hi, I am using structs and am also using property accessors to access those private member fields... TO me this is a good way of handling them, but I find alot of people using direct access to the struct memebers, since structs is just a type similar to a class (with differences I know) why should I allow direct access like that... I looked at the Size and other parts on Control etc and I find its the same way by using property...
6
1725
by: James Pascoe | last post by:
Dear All, Apologies if this is OT. I have a C program which processes an arbitrary number of structs that are stored in a hash table. (The nature of the processing and the layout of the structs is irrelevant to this post, so I wont bore you with the details). My problem is that I need some way of distinguishing the processed
5
3153
by: Paminu | last post by:
Why make an array of pointers to structs, when it is possible to just make an array of structs? I have this struct: struct test { int a; int b;
10
2086
by: Angel | last post by:
I'm using several C functions (in a dll) that receive a struct as parameter. Since I'm doing it in C#, I assume I need to recreate the struct in C# in order to call the function with the required parameter. What would I need to do in order to convert a struct that looks like this: typedef struct { char rsvd0; char iadl1;
5
2774
by: Bidule | last post by:
Hi, I'm trying to sort structs defined as follows: struct combinationRec { float score; char* name; }; The number of structs and the length of the "name" field are not known
5
2928
by: Bilgehan.Balban | last post by:
Hi, I am currently brushing up my c++ knowledge and I would like to ask you about the differences between classes and C structs, in the function/method perspective. 1) Is it correct to say that, a structure definition that includes function pointers only defines the function prototypes to be used with them, but not the actual implementations, whereas in C++, member functions cannot be changed *unless* virtual functions are used, or the
61
3827
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch (myBranch + x) = new Branch(i); // it doesn't x is a loop iterator, i is an int for the constructor to define an array. What am I doing wrong here.
11
2655
by: Cliff Martin | last post by:
Hi, I am reading a fairly large file a line at a time, doing some processing, and filtering out bits of the line. I am storing the interesting information in a struct and then printing it out. This works without any problems. I now would like to filter "duplicate" records. They aren't really duplicate, I can't just qsort as is and eliminate the matching rows. I have number of fields that will be the same, but some of the fields will...
29
2817
by: Dom | last post by:
I'm really confused by the difference between a Struct and a Class? Sometimes, I want just a group of fields to go together. A Class without methods seems wrong, in that it carries too much overhead (I think). A Struct seems more appropriate. At least it is what I would have used in other languages. But since a Struct *can* hold methods, I wander if I am saving anything. If not, why use it?
43
3881
by: JohnQ | last post by:
Are a default constructor, destructor, copy constructor and assignment operator generated by the compiler for a struct if they are not explicitely defined? I think the answer is yes, because "there is no difference between a struct and a class except the public/private access specification" (and a few minor other things). When I create a class, I always start by declaring the default constructor, copy constructor and assignment operator...
0
10149
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11549
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11140
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11320
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8240
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6095
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6317
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4928
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.