Is there a way to make an array of character arrays? i.e. an array of 10 place names, which are character strings? i know you cant do multiple dimension arrays in C, so does this count as one? cheers!
Is there a way to make an array of character arrays? i.e. an array of 10 place names, which are character strings? i know you cant do multiple dimension arrays in C, so does this count as one? cheers!
Yes that is a multi-dimensional array.Outputs-Code:#include <stdio.h> int main(){ char strings[10][9]={ /*10 strings of 9 chars each*/ "String1", "String2", "String3", "String4", "String5", "String6", "String7", "String8", "String9", "String10" }; int loop; for(loop=0;loop<10;loop++){ printf("%s\n",names[loop]); } getchar(); }Code:String1 String2 String3 String4 String5 String6 String7 String8 String9 String10
Windows XP Home Edition - Dev-C++ 4.9.9.2
board.theprogrammingsite.comOriginally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
The first one can hold two strings (like you want), but can't surpass 10 characters (that includes null), each. The second one can hold (point to) five strings and each can be of any length.Code:Rectangular: multidimensional array of chars: char multi[2][10] = {"first", "second"}; Jagged: array of pointers to char(s): char *jagged[5] = {"one", "two", "three", "four", "five"};
- xeddiex
thanks guys