473,831 Members | 2,227 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 2072
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
2019
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
1713
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
3136
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
2078
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
2769
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
2921
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
3788
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
2645
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
2792
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
3849
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
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10778
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
10496
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...
0
10210
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9319
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7750
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
6951
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5622
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...
3
3077
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.