Answer» ^^topic pretty much explains it all --
I WANT to know how to make a table in C++, with customizable SIZE, be able to call a SINGLE CELL at a time, and display the contents of that cell.
I have no clue how to do this so i need to know it from the basics, but my code is virtually empty, just a few do's, if's, and cin/out's, so no conflicts.
Liam.wow your all over the map for programming languages!
I can't really offer any code, but I have a few ideas here.
First thing, I thought of, was a multidimensional array:
int table[5][5];
this obviously won't work, only 36 items, and can't be resized.
I'm not familar with the whole semantics of C, but it might be possible using an Array of an Array of pointers:
Code: [Select]typedef struct { int[]* value } TableDef;
TableDef[]* deftable;
I highly doubt I got that in the first try, but the IDEA is to make an array of an Array of Pointers to Arrays, (obviously you won't just be storing int types, but that's easy to change.
I'm not 100 percent on how one would access it either, my experience with the indirection operator has been unpleasant at best. And don't get me started on const parameters...
Code: [Select]deftable=malloc(SizeOf TableDef*5) for (int i =0;i<5;i++) detable[i]*->value=malloc(SizeOf int*50);
which would create a 2 by 50 table (again, this is just off the top of my head, more for ideas then usable code....)
then, accessing would be something like:
Code: [Select]deftable[2]*->value[5]=12;
Since your using C++, it might be better to do this using classes.
I've had terrible results with anything dynamic in C/C++. its the pointers that always get me, I think. I can deal with pointers in VB6 but they are always long variables, and "dereferencing" the variables means I have to explicitly use "copymemory" to a new variable, so I always know what's what.if you are not doing this for homework/project where you definitely must use C++, i would suggest you use a higher level language such as Python/Perl/Java etc. you should not be dealing with pointers (ever), at least for a programmer not doing low level stuffs.First of all I hardly have the brainpower to run C++ through my head, so I doubt I can dare to try Java, Perl, or Python.
and for me being "all over the map"...
I do VB.Net when i get bored
Batch when I get more bored.
and C++ when i actually care.
Can I have something that is more "usable code" than off the top of your head? maybe some examples pl0x?err, no. I don't really do C++, and probably couldn't make any of my ideas work.
I'd go with ghostdogs suggestion(s), Java is like VB with a more C-like syntax, and can be used to create a small set of aggregate classes to create a useful "chart" data STRUCTURE; Visual Basic would be even easier.
I couldn't get Visual Studio to work when I posted that, and I suck terribly when it comes to actually implementing something in C++ (best I've gotten was a "dynamic function call" library which could be used to call any API without a VB declaration... but that was about 75% assembly).... and it crashed whenever I tried to pass argument, which I couldn't seem to fix.
In either case, C++ unnecessarily complicates things; And I have to agree with ghostdog, Pointers are far too dangerous a coding "feature" too be messed about with casually.
In this case, you could probably get pretty good results from a VB.NET program; or C#. (heck, if you choose VB I might even be useful).
by the way, I never said being all over the map was bad I FOUND a grid that works -- I had a friend send me a tic-tac-toe program and i stripped it down
I know this is irrelevant (but it is the same game, so it is going here), but is there a way to get user input without requring them to press enter afterwords? (I wish to use the 'wasd' and 'uhjk' as arrow keys in this game, and pressing enter after every time is just bad coding)
|