Null Terminator |
|
When using a C-style string (a char array), don't forget to include the null terminator, which is the zero character added to a char array indicating that it has reached its end. Here's an example: char Name[4] = {'J','o','h','n'}; Although there are four chars in the Name array and there are four letter in the name "John," this is incorrect because the string wasn't terminated. Here's the correct way: char Name[5] = {'J','o','h','n','0'}; Now the last letter is zero and terminate the string. This way, when function like strcat or strcpy look at this car array, it will know when the string ends and when it should stop reading it. An alternative to this is to use the STL's string class: string = "John"; |
|
This page is best viewed in 800x600x256. This page was last edited Saturday, July 15, 2000 |