GP32 Storing Words In Array


FabreNZ

Member
Joined
Dec 21, 2004
Messages
132
For my GP32 project, I would like to store 7 words in an array. They will be the days of the week, so the first position in the array should hold the word "Monday", the next "Tuesday", etc. However, creating an array using the code "char[x]" will let me store the specified amount of characters, rather than words. How do I store 7 words in an array?
 
The easiest way to store variable length strings in an array is to store a pointer to the start of the string rather than all of the chars that make up the string.


char *days_of_week[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};

Notice the *, this means you only want to store the location of the variable in memory. So if you pass days_of_week[2] to a text function, it will process all of the characters starting from that memory location stored in days_of_week[2] until it encounters a null value ( 0x00 ).

Does that make sense?
 
Back
Top