#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    7
    Rep Power
    0

    Question about structures :)


    Can I ask is there a way to access two or more variables inside a structure

    an example is that I would like to access a coordinate x and y and a value in a structure is there a way I could access them at the same time to access their value

    Ps : their value is already declared I need to know how to access them :(

    advance thank you :)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    71
    Rep Power
    2
    I'm not sure what you mean by 'access them at the same time to access their value'?

    Do you mean with threads? Do mean packing the values into one register size variable?

    Could you elaborate with a detailed example or pseudo code?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    7
    Rep Power
    0
    like this one

    struct map
    {

    int x;
    int y;

    int value;

    }

    could I access the three at the same time?

    like value of (x,y) :)
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    71
    Rep Power
    2
    Originally Posted by Sinoka56
    like this one

    struct map
    {

    int x;
    int y;

    int value;

    }

    could I access the three at the same time?

    like value of (x,y) :)
    Again, I'm not sure what you mean by 'the same time'. Maybe you could explain why you want access them at the same time.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    7
    Rep Power
    0
    because I have sort of an exercise where in value is the value of the tile and x and y are the coordinates :)

    like this

    110
    100
    101

    I wanted to get the 1 at the top left of the map and everything is already encoded :)
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Post


    first.
    limited of y .example: 0 < y < 100

    second.
    value = x * 100 +y

    => x = value/100 ;and y = value % 100;

    do you mean?


    im new member . im studing English. forward to help :D
  12. #7
  13. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481

    accessing structure members


    Code:
    struct map {
      int x,y,value;
    } fxy;
    
    fxy.x = 3;
    fxy.y = 2;
    fxy.value = 57;
    
    fxy.y, fxy.y;
    [code]Code tags[/code] are essential for python code and Makefiles!
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    7
    Rep Power
    0
    Originally Posted by b49P23TIvg
    Code:
    struct map {
      int x,y,value;
    } fxy;
    
    fxy.x = 3;
    fxy.y = 2;
    fxy.value = 57;
    
    fxy.y, fxy.y;
    can I the fxy.x or fxy.y I need to input the width and Height of the map?

    and how do I print it? :)
  16. #9
  17. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481
    fxy.x

    may be used just like any other int variable
    Naturally the same is true for the other structure members.
    [code]Code tags[/code] are essential for python code and Makefiles!
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    7
    Rep Power
    0
    not that :)

    x,y,value already has values encoded

    x and y are the coordinates and value is the value in the coordinates I just want to know how to access them at the same time
  20. #11
  21. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,162
    Rep Power
    2222
    Accessing each individual struct field is trivial.

    Extremely trivial!

    But our answers do not satisfy you. Which tells us that you are not asking the right question.

    Over 30 years ago, British writer Douglas Adams wrote a science-fiction spoof, "The Hitchhiker's Guide to the Galaxy". In that story, the most powerful computer ever built, Deep Thought, was given the task of coming up with the Ultimate Answer to Life, the Universe, and Everything. Millions of years later, it came up with the answer: 42. Well, of course the Ultimate Answer had no meaning unless you knew the Ultimate Question, which Deep Thought was incapable of, but it could design the computer that could come up with the Ultimate Question, and it would incorporate biological matrices in its computation, and it would be called "The Earth". And five minutes before final printout, it was destroyed to make way for a hyper-spatial bypass (like a freeway junction).

    All of which is a way of saying that you are not asking the right question. We know the answer, but we don't understand the question.

    Is there some special way in which the data is being encrypted or formatted?

    Comments on this post

    • b49P23TIvg agrees : capital letters won't help!
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    7
    Rep Power
    0
    struct map2 {
    /*position of the tile on the map*/
    int x;
    int y;

    /*current value of the tile*/
    int value;
    };

    /*map data structure represents the map data*/
    struct map1 {

    /*dimensions of the map*/
    int w;
    int h;

    /*2D grid of tiles representing the map*/
    struct tile *grid;
    };

    we were given a .map file

    3 3
    101
    100
    111

    and everything is encoded in a .o file
    like

    [1]01
    100
    111

    I would like to find out how could access the [1] from the quoted code :)
  24. #13
  25. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481
    Glossary

    "file" data in long term storage accessible through the file system.

    ".map file" any sort of file, often associated as an intermediate program linker file.

    ".o file" any sort of file, usually the object file created by a compiler on a unix system.



    everything is encoded in a .o file
    Maybe you just need to write a main function which you link to the .o file? The project is a little tricky without documentation, but I have some friends in Russia...



    What is the relationship between your .map file and the struct map ???



    This gawk program prints the first character of the second line of input files

    gawk -F '' '2==FNR{print $1}'




    Are x and y in your structure the column and row of data from your file, and the value member equal to the numerical value of the character in the file? And do you need an array of arrays of these structures? And if so, why bother storing x and y? (Yes, you might need them.)
    Last edited by b49P23TIvg; October 15th, 2012 at 09:28 AM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    7
    Rep Power
    0
    Nevermind :)

    Thanks for all the help

    I just found out that the *grid was a pointer and all the values was in it :)
  28. #15
  29. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481
    If you have further questions for devshed forums please provide much more information initially. This simply was not worth while.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo