I'm trying to create an array of strings that can be randomized and limited to a certain x number of strings.
If the array could be randomized I could pick the first x strings and that would work fine.
I'm trying to use code like this currently
NSString *statements[9]; statements[0] = @"hello";
This seems to work but the array seems to be full of rubbish data.
Can someone help me in the right direction. (is the memory allocation being done in the wrong way?
Thanks
To declare an array in Objective-C, we use the following syntax. type arrayName [ arraySize ]; type defines the data type of the array elements. type can be any valid Objective-C data type.
Here is how an array of C string can be initialized: #define NUMBER_OF_STRING 4 #define MAX_STRING_SIZE 40 char arr[NUMBER_OF_STRING][MAX_STRING_SIZE] = { "array of c string", "is fun to use", "make sure to properly", "tell the array size" };
We can have an array with strings as its elements. Thus, we can define a String Array as an array holding a fixed number of strings or string values. String array is one structure that is most commonly used in Java. If you remember, even the argument of the 'main' function in Java is a String Array.
Examples of Array String in C In this table representation, each row (first subscript) defines as the number of strings to be stored and column (second subscript) defines the maximum length of the strings. As the above example is for two-dimensional arrays so the pointer points to each string of the array.
Do you want an array with nine strings in it?
[NSArray arrayWithObjects: @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", nil]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With