Array of Strings
jabramson
Posts: 106
Is it possible to do an array with strings (or characters) in it?
I'd like to reference this by array index
I'd like to reference this by array index
cINPUTNAMES[] = {'INPUT #1', 'INPUT #2', 'INPUT #3', 'INPUT #4', 'INPUT #5', 'INPUT #6', 'INPUT #7', 'INPUT #8', 'INPUT #9', 'INPUT #10', 'INPUT #11', 'INPUT #12', 'INPUT #13', 'INPUT #14', 'INPUT #15', 'INPUT #16', 'INPUT #17', 'INPUT #18', 'INPUT #19', 'INPUT #20', 'INPUT #21', 'INPUT #22', 'INPUT #23', 'INPUT #24', 'INPUT #25', 'INPUT #26', 'INPUT #27', 'INPUT #28', 'INPUT #29', 'INPUT #30', 'INPUT #31', 'INPUT #32' }
0
Comments
A string is an array of chars. What you are declaring is an array of arrays of chars. What I wrote above describes an array of 32 strings and each one contains at most 10 chars.
cINPUTNAMES[2] -> 'INPUT #2'
cINPUTNAMES[2][8] -> '2'
I'm assuming this was an academic example and you are going to be storing more interesting strings than 'INPUT #2' - otherwise you could just use itoa and forgo the array altogether
[] [] won't work
but
[] [3] will
When dealing with 2 or more arrays the last array needs to be defined with a number in the brackets not just the array itself.