Sign in to follow this  

passing 2D array to struct

This topic is 1781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

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

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

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

This topic is 1781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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