C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 13th, 2012, 08:39 PM
Sinoka56 Sinoka56 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 Sinoka56 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m 28 sec
Reputation 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

Reply With Quote
  #2  
Old October 13th, 2012, 09:46 PM
G4143 G4143 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 71 G4143 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 39 m 39 sec
Reputation Power: 1
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?

Reply With Quote
  #3  
Old October 13th, 2012, 10:05 PM
Sinoka56 Sinoka56 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 Sinoka56 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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)

Reply With Quote
  #4  
Old October 13th, 2012, 10:14 PM
G4143 G4143 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 71 G4143 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 39 m 39 sec
Reputation Power: 1
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.

Reply With Quote
  #5  
Old October 14th, 2012, 03:05 AM
Sinoka56 Sinoka56 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 Sinoka56 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #6  
Old October 14th, 2012, 09:31 AM
Zuee Zuee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 1 Zuee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 37 sec
Reputation 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

Reply With Quote
  #7  
Old October 14th, 2012, 01:07 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,389 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 22 m 25 sec
Reputation Power: 383
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!

Reply With Quote
  #8  
Old October 14th, 2012, 06:01 PM
Sinoka56 Sinoka56 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 Sinoka56 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #9  
Old October 14th, 2012, 08:17 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,389 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 22 m 25 sec
Reputation Power: 383
fxy.x

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

Reply With Quote
  #10  
Old October 15th, 2012, 02:30 AM
Sinoka56 Sinoka56 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 Sinoka56 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m 28 sec
Reputation 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

Reply With Quote
  #11  
Old October 15th, 2012, 02:46 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,141 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 23 h 52 m 21 sec
Reputation Power: 1974
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!

Reply With Quote
  #12  
Old October 15th, 2012, 05:03 AM
Sinoka56 Sinoka56 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 Sinoka56 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #13  
Old October 15th, 2012, 09:25 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,389 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 22 m 25 sec
Reputation Power: 383
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 09:28 AM.

Reply With Quote
  #14  
Old October 16th, 2012, 09:00 AM
Sinoka56 Sinoka56 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 Sinoka56 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #15  
Old October 16th, 2012, 09:55 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,389 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 22 m 25 sec
Reputation Power: 383
If you have further questions for devshed forums please provide much more information initially. This simply was not worth while.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Question about structures :)

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap