Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

passing 2D array to struct

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
6 replies to this topic

#1 hikarihe   Members   

243
Like
0Likes
Like

Posted 02 March 2013 - 05:31 AM

how do you do it?

 

I have this array:

 

 

char textureFileNames[ NUMBER_OF_TEXTURES ][ 48 ];
 

 

 

and:

 

 

// this is what I want
examplestruct.filenames = textureFileNames;
 

 

  • how do I declare the struct member so that it allows me to pass the address of my array to the member?
  • then how do i assign the address of the 2D array to the member?

 

any help appreciated happy.png



#2 Brother Bob   Moderators   

10281
Like
2Likes
Like

Posted 02 March 2013 - 05:39 AM

Declare your filenames field as follows:

struct myStruct {
    char (*filenames)[48];
};


#3 hikarihe   Members   

243
Like
0Likes
Like

Posted 02 March 2013 - 05:44 AM

It compiles, thank u!



#4 cozzie   Members   

4972
Like
0Likes
Like

Posted 02 March 2013 - 10:25 AM

Hi, never the less, you could do it maybe even easier making filenames a std::string fienames[NUMBER_OF_TEXTURES];

also easy to assing, like:

 

filenames[x] = "something";

filenames[x] += somevar; etc.

 

this gives great flexibility in my opinion, compared to using array of chars

(I use it to choose the right filename for effects, based on shadermodel, number of lights etc)


Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me


#5 hikarihe   Members   

243
Like
0Likes
Like

Posted 02 March 2013 - 12:23 PM

Hi, never the less, you could do it maybe even easier making filenames a std::string fienames[NUMBER_OF_TEXTURES];

also easy to assing, like:

 

filenames[x] = "something";

filenames[x] += somevar; etc.

 

this gives great flexibility in my opinion, compared to using array of chars

(I use it to choose the right filename for effects, based on shadermodel, number of lights etc)

is this allowed in C? I've never used std::string before but I think it's for C++ right?

 

Also isn't the string vulnerable to being overwritten by other data since you don't explicitly specify its size?



#6 Paradigm Shifter   Members   

5832
Like
1Likes
Like

Posted 02 March 2013 - 12:30 PM

Yeah, that is C++ only. It really makes things easier though, string handling in C is a pain.

 

C++ std::strings are automatically resized so overwriting isn't a problem.


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#7 cozzie   Members   

4972
Like
0Likes
Like

Posted 02 March 2013 - 04:02 PM

Sorry, it's C++ indeed.

Don't know if you have other mandatory reasons to stay with C, if not, I'd go for std::string


Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.