Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
October 13th, 2012, 09:39 PM
 Sinoka56
Registered User

Join Date: Oct 2012
Posts: 7
Time spent in forums: 55 m 28 sec
Reputation Power: 0

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

#2
October 13th, 2012, 10:46 PM
 G4143
Contributing User

Join Date: Oct 2012
Posts: 71
Time spent in forums: 1 Day 7 h 39 m 39 sec
Reputation 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?

#3
October 13th, 2012, 11:05 PM
 Sinoka56
Registered User

Join Date: Oct 2012
Posts: 7
Time spent in forums: 55 m 28 sec
Reputation 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)

#4
October 13th, 2012, 11:14 PM
 G4143
Contributing User

Join Date: Oct 2012
Posts: 71
Time spent in forums: 1 Day 7 h 39 m 39 sec
Reputation Power: 2
Quote:
 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.

#5
October 14th, 2012, 04:05 AM
 Sinoka56
Registered User

Join Date: Oct 2012
Posts: 7
Time spent in forums: 55 m 28 sec
Reputation 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

#6
October 14th, 2012, 10:31 AM
 Zuee
Registered User

Join Date: Oct 2012
Posts: 1
Time spent in forums: 27 m 37 sec
Reputation Power: 0

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

#7
October 14th, 2012, 02:07 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,218
Time spent in forums: 1 Month 3 Weeks 2 Days 18 h 51 m 46 sec
Reputation Power: 455
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!

#8
October 14th, 2012, 07:01 PM
 Sinoka56
Registered User

Join Date: Oct 2012
Posts: 7
Time spent in forums: 55 m 28 sec
Reputation Power: 0
Quote:
 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?

#9
October 14th, 2012, 09:17 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,218
Time spent in forums: 1 Month 3 Weeks 2 Days 18 h 51 m 46 sec
Reputation Power: 455
fxy.x

may be used just like any other int variable
Naturally the same is true for the other structure members.

#10
October 15th, 2012, 03:30 AM
 Sinoka56
Registered User

Join Date: Oct 2012
Posts: 7
Time spent in forums: 55 m 28 sec
Reputation Power: 0
not that

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

#11
October 15th, 2012, 03:46 AM
 dwise1_aol
Contributing User

Join Date: Jan 2003
Location: USA
Posts: 6,893
Time spent in forums: 3 Months 1 Day 20 h 47 m 27 sec
Reputation Power: 2199
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?
b49P23TIvg agrees: capital letters won't help!

#12
October 15th, 2012, 06:03 AM
 Sinoka56
Registered User

Join Date: Oct 2012
Posts: 7
Time spent in forums: 55 m 28 sec
Reputation Power: 0
Quote:
 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

#13
October 15th, 2012, 10:25 AM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,218
Time spent in forums: 1 Month 3 Weeks 2 Days 18 h 51 m 46 sec
Reputation Power: 455
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.

Quote:
 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 10:28 AM.

#14
October 16th, 2012, 10:00 AM
 Sinoka56
Registered User

Join Date: Oct 2012
Posts: 7
Time spent in forums: 55 m 28 sec
Reputation 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

#15
October 16th, 2012, 10:55 AM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,218
Time spent in forums: 1 Month 3 Weeks 2 Days 18 h 51 m 46 sec
Reputation Power: 455
If you have further questions for devshed forums please provide much more information initially. This simply was not worth while.

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Question about structures :)