Go Down

Topic: String or Char Arrays Length Definition (Read 2 times) previous topic - next topic

tavovalencia


Code: [Select]
         Name[9] = '\0';
For an array of 9 elements, what are the valid index values? Hint: 9 is not one of them.


array of 9 elements = 8 valid values. right? I don't really get what you're suggesting?

PeterH


array of 9 elements = 8 valid values. right?


No. The first element is array[0]. Count up to nine elements and see which index values you used.
I only provide help via the forum - please do not contact me for private consultancy.

tavovalencia



array of 9 elements = 8 valid values. right?


No. The first element is array[0]. Count up to nine elements and see which index values you used.


According to your explanation, there would be 10. But according to http://arduino.cc/en/Reference/Array
Quote

int mySensVals[6] = {2, 4, -8, 3, 2};
char message[6] = "hello";


so there are 5 values in the first and 5 letters in the second. I still don't get your point?... with my code loaded... press a key and hold until 20 or more chars have appeared in the dialog and then press enter... the error message appears several times and sometimes other chars bellow...

KeithRB

lets look at index vs character position:

Index    Char position
0               1 (first character)
1               2
2               3
3               4
4               5
6               7
7               8 (last character)
8               9 (nul goes here at arry[8]

tavovalencia


  • INPUT: "1" ; OUTPUT: "1"

  • INPUT: "12345" ; OUTPUT: "12345"

  • INPUT: "12345678" ; OUTPUT: "12345678"

  • INPUT: "123456789" ; OUTPUT: "Invalid Input, please enter 3 to 8 characters"

  • INPUT: "12345678901" ; OUTPUT: Blank line, "Invalid Input, please enter 3 to 8 characters" & line with "1"

  • INPUT: "123456789012" ; OUTPUT: Blank line, "Invalid Input, please enter 3 to 8 characters" & line with "12"

  • INPUT: "012345678901234567890123" ; OUTPUT: "Invalid Input, please enter 3 to 8 characters" twice& line with "0123"



I would love to have just the ERROR ONCE. Any ideas, please!!!!

Go Up