Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: [C++] Create a table that holds information in each cell and can display it?  (Read 4518 times)

0 Members and 1 Guest are viewing this topic.

liambiscuit

    Topic Starter


    Hopeful

    ^^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.
    " When the rich wage war its the Poor who die "
            Linkin Park



    Whoever said that nothing is impossible has obviously never tried to slam a revolving door. -- Lauren

    You cannot buy your friends but you can buy them pizza - AzureBlade49

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    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.
    I was trying to dereference Null Pointers before it was cool.

    gh0std0g74



      Apprentice

      Thanked: 37
      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.

      liambiscuit

        Topic Starter


        Hopeful

        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?
        " When the rich wage war its the Poor who die "
                Linkin Park



        Whoever said that nothing is impossible has obviously never tried to slam a revolving door. -- Lauren

        You cannot buy your friends but you can buy them pizza - AzureBlade49

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        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  :P
        I was trying to dereference Null Pointers before it was cool.

        liambiscuit

          Topic Starter


          Hopeful

          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)
          " When the rich wage war its the Poor who die "
                  Linkin Park



          Whoever said that nothing is impossible has obviously never tried to slam a revolving door. -- Lauren

          You cannot buy your friends but you can buy them pizza - AzureBlade49