473,766 Members | 2,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing a Structure Using a Pointer

Here is what I have:

struct SubList
{
int BookId;
int WFreq;
};

struct Listing
{
string Word;
int BookCnt;
int TWFreq; //total frequency in all books
SubList * ptr[10];

};
A Listing structure will be used as an array like so:
Listing a[100];

Now, the Listing pointer variable s points to an array of SubList
structure, so 1 Listing can point to more than one SubList. If a word
is found in more than one book, it will have one entry in Listing which
then points to SubList with all the book id's it is found in. Either
way, if a word is found in Listing then it is bound to have a book id
and so it's s pointer will have to point to SubList with at least one
entry.
I am a bit confused as to how I'll be accessing this SubList
structure. So far, this is what I have been able to come up with, but
needless to say, it's wrong:

a[i].Word = FullBase[FBI].Word;
a[i].BookCnt = 1;
a[i].TWFreq = FullBase[FBI].WordFreq;

//now make entry for this word into SubList
a[i].ptr = new Posting;
a[i].(ptr[0]->BookId) = BookId_tmp;

In the last line, I get an error that the '(' is illegal (followed by a
gazillion other errors, but I'm sure that it is the parenthesis
notation that is wrong).

Gratefull for any help
SA

Nov 10 '05 #1
9 2342
* sakitah:
Here is what I have:

struct SubList
{
int BookId;
int WFreq;
};

struct Listing
{
string Word;
int BookCnt;
int TWFreq; //total frequency in all books
SubList * ptr[10];

};
A Listing structure will be used as an array like so:
Listing a[100];

...
Gratefull for any help


Use standard library collection classes such as std::vector (instead of
raw arrays and pointers), and use meaningful names.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 10 '05 #2
sakitah wrote:
Here is what I have:

struct SubList
{
int BookId;
int WFreq;
};

struct Listing
{
string Word;
int BookCnt;
int TWFreq; //total frequency in all books
SubList * ptr[10];

};
Not that its not 'ptr' that is the array of SubList pointers, it is
Listing::ptr.
A Listing structure will be used as an array like so:
Listing a[100];

Now, the Listing pointer variable s points to an array of SubList
structure, so 1 Listing can point to more than one SubList. If a word
is found in more than one book, it will have one entry in Listing which
then points to SubList with all the book id's it is found in. Either
way, if a word is found in Listing then it is bound to have a book id
and so it's s pointer will have to point to SubList with at least one
entry.
I am a bit confused as to how I'll be accessing this SubList
structure. So far, this is what I have been able to come up with, but
needless to say, it's wrong:

a[i].Word = FullBase[FBI].Word;
a[i].BookCnt = 1;
a[i].TWFreq = FullBase[FBI].WordFreq;

//now make entry for this word into SubList
a[i].ptr = new Posting;
a[i].(ptr[0]->BookId) = BookId_tmp;
Hence it is incorrect to index ptr, you must index a[i].ptr
The correct code would be

a[i].ptr[0]->BookId = BookId_tmp;

In the last line, I get an error that the '(' is illegal (followed by a
gazillion other errors, but I'm sure that it is the parenthesis
notation that is wrong).


As an aside, it is recommended that one should prefer vector or other
containers of the standard library over arrays.

Nov 10 '05 #3

"sakitah" <sa*********@ya hoo.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Here is what I have:

struct SubList
{
int BookId;
int WFreq;
};

struct Listing
{
string Word;
int BookCnt;
int TWFreq; //total frequency in all books
SubList * ptr[10];

};
A Listing structure will be used as an array like so:
Listing a[100];

Now, the Listing pointer variable s points to an array of SubList
structure, so 1 Listing can point to more than one SubList. If a word
is found in more than one book, it will have one entry in Listing which
then points to SubList with all the book id's it is found in. Either
way, if a word is found in Listing then it is bound to have a book id
and so it's s pointer will have to point to SubList with at least one
entry.
I am a bit confused as to how I'll be accessing this SubList
structure. So far, this is what I have been able to come up with, but
needless to say, it's wrong:

a[i].Word = FullBase[FBI].Word;
a[i].BookCnt = 1;
a[i].TWFreq = FullBase[FBI].WordFreq;

//now make entry for this word into SubList
a[i].ptr = new Posting;
a[i].(ptr[0]->BookId) = BookId_tmp;

In the last line, I get an error that the '(' is illegal (followed by a
gazillion other errors, but I'm sure that it is the parenthesis
notation that is wrong).


Um,

a[i].ptr[0]->BookId = BookId_tmp;

The compiler told you the problem.

-Mike
Nov 10 '05 #4
The procedure to access the ptr[] structures was already mentioned
(what does "ptr" mean - do you know this when you look at your hundret
lines of code 6 month later?), as well as the recommendation to use
std::vector and friends.

You surely have a good reason to use structures rather than classes?
Eckhard

Nov 10 '05 #5
On 2005-11-10, sakitah <sa*********@ya hoo.com> wrote:
Here is what I have:

struct SubList
{
int BookId;
int WFreq;
};

struct Listing
{
string Word;
int BookCnt;
int TWFreq; //total frequency in all books
SubList * ptr[10];

};
A Listing structure will be used as an array like so:
Listing a[100];

Now, the Listing pointer variable s
There is no variable s.
points to an array of SubList structure, so 1 Listing can point
to more than one SubList. If a word is found in more than one
book, it will have one entry in Listing which then points to
SubList with all the book id's it is found in. Either way, if
a word is found in Listing then it is bound to have a book id
and so it's s pointer will have to point to SubList with at
least one entry.


Where are you going to find books whose vocabulary is limited to
100 words?

Why are there 10 SubLists for each word?

--
Neil Cerutti
Nov 10 '05 #6
I tried it like this (without the '()')

a[i].ptr = new SubList;
a[i].ptr[0]->BookId = BookId_tmp;

and sadly it refused to compile....I get an error at line:
a[i].ptr = new SubList;

with the following error:
C:\Documents and Settings\B only B\My
Documents\Maste r's\FaLl05\Cs68 1\Inverted
Files\InvertedF ile\InvertedFil e.cpp(125) : error C2440: '=' : cannot
convert from 'struct SubList*' to 'struct SubList*[10]'
There are no conversions to array types, although there are
conversions to references or pointers to arrays

I tried commenting out that line and it did compile but when run, the
program stops at that line, which does make sense.....I wasnt expecting
it to work anyways.

Obviuosly I need that line in there, just dont know how to write it
correctly.
Help

Nov 11 '05 #7

sakitah wrote:
I tried it like this (without the '()')

a[i].ptr = new SubList;


ptr is the name of the array, not a pointer. it cannot be changed.

Nov 11 '05 #8
sakitah wrote:
I tried it like this (without the '()')

a[i].ptr = new SubList;
a[i].ptr[0]->BookId = BookId_tmp;

and sadly it refused to compile....I get an error at line:
a[i].ptr = new SubList;

with the following error:
C:\Documents and Settings\B only B\My
Documents\Maste r's\FaLl05\Cs68 1\Inverted
Files\InvertedF ile\InvertedFil e.cpp(125) : error C2440: '=' : cannot
convert from 'struct SubList*' to 'struct SubList*[10]'
There are no conversions to array types, although there are
conversions to references or pointers to arrays


You are not paying attention to compiler's errors. ptr is an array 10 of
pointer to int. Array name is a not modifiable lvalue, and you are
assigning struct SubList* to it. you want ..

a[i].ptr[0] = new SubList;

Krishanu

Nov 11 '05 #9
Krishanu Debnath wrote:
sakitah wrote:
I tried it like this (without the '()')

a[i].ptr = new SubList;
a[i].ptr[0]->BookId = BookId_tmp;

and sadly it refused to compile....I get an error at line:
a[i].ptr = new SubList;

with the following error:
C:\Documents and Settings\B only B\My
Documents\Maste r's\FaLl05\Cs68 1\Inverted
Files\InvertedF ile\InvertedFil e.cpp(125) : error C2440: '=' : cannot
convert from 'struct SubList*' to 'struct SubList*[10]'
There are no conversions to array types, although there are
conversions to references or pointers to arrays

You are not paying attention to compiler's errors. ptr is an array 10 of


ptr is an array 10 of pointer to SubList, darn.
pointer to int. Array name is a not modifiable lvalue, and you are
assigning struct SubList* to it. you want ..

a[i].ptr[0] = new SubList;

Krishanu


Krishanu
Nov 11 '05 #10

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

Similar topics

5
9119
by: Jason | last post by:
How do you access an int pointer inside a struct. This is how it seems like it would work to me, but it doesn't... struct maze { int num; int * roomnum; }; void setmaze(struct maze * maze) { maze->num = 1; //this is equivelant to: (*maze).num = 1
6
2082
by: archilleswaterland | last post by:
structures typedef struct{ char name; int age; float balance; }account; account xyx; accout *ptr;
2
1313
by: Ted Sung | last post by:
Hi, I'm using P/Invoke to call some C functions from a DLL. My C function returns a pointer to a large C structure. I store this returned pointer in an IntPtr C# variable. I would now like to access the data in this structure. What is the best way to do this? The structure is so large that I can't lay it out as a C# struct. What else could I do?
8
3022
by: nkrisraj | last post by:
Hi, I have a following structure: typedef struct { RateData rdr; int RateID; char RateBalance; } RateInfo;
0
1984
by: harsha1305 | last post by:
Hi all, I need to create a pointer to array of structure. Definition of structure: typedef struct { char b_name; unsigned long int sig; unsigned long int count; volatile unsigned char *Su_buffer;
16
8026
by: quantumred | last post by:
Can I use pointer arithmetic on the members of a structure in the following way? Should I be worried about structure padding? This works in my debugger but I wonder if I'm bending some rule here. struct char_struct { unsigned char a; unsigned char b; unsigned char c; unsigned char d; };
2
1664
by: leby | last post by:
Hi all, Thanks for haveing this group. I am in search of a solution to Q. Thought of geeting the same from experts. I have c files to generate shared libraries (not relating to linux,unix,windows) and would like to share data with other libraries. For Eg:. Fileone.c --------gives me Fileone.so input to this is a text file Country.txt (set of integers)
7
1801
by: =?Utf-8?B?U3RlcGhhbmllIERvaGVydHk=?= | last post by:
I am trying to call some API functions written in C++ from my VB .NET 2003 application and am running into some difficulty in passing structures to a function. It is probably due to the types I'm declaring for the structure members not lining up properly, but I don't know how to declare them correctly. The C++ types being used are ULONG, LONG and LPWSTR. Does anyone know what the VB type should be for each of these? Thanks, Stephanie
4
1971
by: yugidnu | last post by:
Hi all, I have the following problem. I have to access different types of structures getting passed via a void pointer. I have the code snippet here. --------------------------------------------------------------------------------------------------------------------- /* N structures each having different type of member variable .*/
0
9568
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
10168
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
10008
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
9837
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
8833
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
7381
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
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
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
3532
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.