473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 2314
* 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*********@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.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*********@yahoo.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\Master's\FaLl05\Cs681\Inverted
Files\InvertedFile\InvertedFile.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\Master's\FaLl05\Cs681\Inverted
Files\InvertedFile\InvertedFile.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\Master's\FaLl05\Cs681\Inverted
Files\InvertedFile\InvertedFile.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
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)...
6
by: archilleswaterland | last post by:
structures typedef struct{ char name; int age; float balance; }account; account xyx; accout *ptr;
2
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...
8
by: nkrisraj | last post by:
Hi, I have a following structure: typedef struct { RateData rdr; int RateID; char RateBalance; } RateInfo;
0
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...
16
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. ...
2
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...
7
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...
4
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. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
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...
0
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...
0
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,...

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.