Archived

This topic is now archived and is closed to further replies.

johnnyBravo

Question on arrays way number works

Recommended Posts

say with: int numbers[10]; i would be able to enter 10 numbers from 0 to 9 but with: char text[5]="here"; it will only accept the four letters not five. but with: char text2[5]; i can do text2[0]=''a'' ..etc ..etc ..etc text2[4]=''e'' why is this?

Share this post


Link to post
Share on other sites
You can certainly put five *letters* in the text array, but then it won''t be a valid C string (for use with strcpy, strstr, strlen, etc.), because it''s not null-terminated. By the way, in your example, text is holding five *characters*: ''h'', ''e'', ''r'', ''e'', and ''\0''.

--
Dave Mikesell Software & Consulting

Share this post


Link to post
Share on other sites