Click to See Complete Forum and Search --> : Arrays


crkp
March 10th, 2005, 05:53 PM
In C, how can I initialize an array set to include a user-defined parameter?

For example:

userPattern = userInputStruct->pattern;
dataPattern[] = { userPattern };

Of course, that is not the correct syntax. However, I wanted the contents of userPattern (or the data stored in userInputStruct->pattern), which is inputted by the user at run-time, to populate into the dataPattern array. This is for C programming. I couldn't find a forum for 'C' programming, so thought that perhaps this is where it would fit best.

Thanks for all your help!!!

Kheun
March 10th, 2005, 06:50 PM
You are coming to the right place.

Since C doesn't support creating variable size array on the stack, you have to specify the size in the declaration of the array. To populate the array, you can then specify the index.


MyPattern dataPattern[2];
dataPattern[0] = userPattern;

Axter
March 10th, 2005, 09:04 PM
In C, how can I initialize an array set to include a user-defined parameter?

For example:

userPattern = userInputStruct->pattern;
dataPattern[] = { userPattern };

Of course, that is not the correct syntax. However, I wanted the contents of userPattern (or the data stored in userInputStruct->pattern), which is inputted by the user at run-time, to populate into the dataPattern array. This is for C programming. I couldn't find a forum for 'C' programming, so thought that perhaps this is where it would fit best.

Thanks for all your help!!!
What is the type for dataPattern?
We can give you a better answer if you could tell us what types you're trying to use.