| | |
array problems
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
Hello,
I've got a 2 diemsional array that ments to represent this:
Name Address
A 1
B 2
C 3
I've got the following code written for this:
should that be:
And I've got a pointer that populates only the name:
But this doesnt work and not sure why.
My overall question is :
*Have I delcare an array that takes a stream of chars properly?
I've got a 2 diemsional array that ments to represent this:
Name Address
A 1
B 2
C 3
I've got the following code written for this:
C++ Syntax (Toggle Plain Text)
char * tableArray[10];
should that be:
C++ Syntax (Toggle Plain Text)
char * tableArray[10][10];?
And I've got a pointer that populates only the name:
C++ Syntax (Toggle Plain Text)
char * ptr = tableArray[sti];
My overall question is :
*Have I delcare an array that takes a stream of chars properly?
•
•
Join Date: Jul 2005
Posts: 1,753
Reputation:
Solved Threads: 283
A table of strings with more than one string per row would be a three dimensional array of char. Say the table contained one string for the name and one string for the address per row of the table:
Name Address
John Milwaukee
Jane Miami
Depending on your needs, such a table could be declared using any of the following:
char ***names;
char **names[];
char *names[][];
char names[][][];
Name Address
John Milwaukee
Jane Miami
Depending on your needs, such a table could be declared using any of the following:
char ***names;
char **names[];
char *names[][];
char names[][][];
•
•
Join Date: Jul 2005
Posts: 1,753
Reputation:
Solved Threads: 283
Linked lists and arrays each have their benefits and detriments, depending on the task. With a linked list you will need to create a programmer declared container type to hold the information stored in the list. This can often be accomplished by using a struct/class that contains both the information to be stored and the location/address of the next link/node in the list. You could also use an array of programmer declared type rather than a linked list of programmer declared type so you would only need a single dimensional array rather than a three dimensional array.
•
•
•
•
Originally Posted by Acidburn
I like that but never done it , could you explain in detail?
in C++, struct and class are both actually the same thing... well, almost.. they have one minor difference which isn't important at the moment.
a struct (the name originally came from 'data structure') is conceptually very similar to a table layout in an MS Access database - in fact, I suspect that most databases use the term "data structure" too.
At the basic level, it will typically contain one or more "fields" (called member variables), and every record (object) created has its own value for each of these fields.
eg,
C++ Syntax (Toggle Plain Text)
struct MyStruct { std::string foreame; std::string surname; char middleInitial; int age; } int main() { MyStruct MyPerson; MyPerson.forename = "Fred"; MyPerson.surname = "Bloggs"; MyPerson.middleInitial = 'E'; MyPerson.age = 36; // etc. }
You can make an array of UDTs in exactly the same way as you'd create an array of int or any other built-in type. ie,
C++ Syntax (Toggle Plain Text)
MyStruct PeopleDatabase[50]; PeopleDatabase[0].forename = "Joseph";
Note - above is C++ code, C uses a slightly different syntax for creating an object of MyStruct. If you are using C++, then this is probably your first step into writing Object-orientated code.
![]() |
Similar Threads
- Array problems (C++)
- Array problems (C++)
- array problems (C++)
- Problem installing XP on a SATA Striping Array (Storage)
- error 88:'(' expected when trying to display an array any help (Pascal and Delphi)
Other Threads in the C++ Forum
- Previous Thread: printing meter yards feet
- Next Thread: Templates
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






