Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Title: Should be "Null terminate" (no hyphen) when a verb. I didn't make the change because I think this breaks links. Ed.

Wiki Markup
Null-terminated byte strings (NTBS) must contain a null-termination character at or before the address of the last element of the array before they can be safely passed as arguments to standard string-handling functions, such as {{strcpy()}} or {{strlen()}}.  This is because these functions, as well as other string-handling functions defined by C99 \[[ISO/IEC 9899-1999|AA. C References#ISO/IEC 9899-1999]\], depend on the existence of a null-termination character to determine the length of a string.  Similarly, NTBS must be null
-
 terminated before iterating on a character array where the termination condition of the loop depends on the existence of a null-termination character within the memory allocated for the string, as in the following example:

Code Block
size_t i;
char ntbs[16];
/* ... */
for (i = 0; i < sizeof(ntbs); ++i) {
  if (ntbs[i] == '\0') break;
  /* ... */
}

...