Sign in to follow this  
hikarihe

passing 2D array to struct

Recommended Posts

hikarihe    243

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

Share this post


Link to post
Share on other sites
cozzie    5029

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)

Share this post


Link to post
Share on other sites
hikarihe    243

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this