Strings are a fundamental concept in software engineering, but they are not a built-in type in C. Null-terminated byte strings (NTBS) consist of a contiguous sequence of characters terminated by and including the first null character, and are supported in C as the format used for string literals. The C programming language supports the following types of null-terminated byte strings: single-byte character strings, multibyte character strings, and wide character strings. Single-byte and multibyte character strings are both described as null-terminated byte strings, which are also referred to as "narrow character strings".
A pointer to a singlenull-terminated byte or multibyte character string points to its initial character. The length of the string is the number of bytes preceding the null character, and the value of the string is the sequence of the values of the contained characters, in order.
A wide string is a contiguous sequence of wide characters (of type wchar_t
) terminated by and including the first null wide character. A pointer to a wide string points to its initial (lowest addressed) wide character. The length of a wide string is the number of wide characters preceding the null wide character, and the value of a wide string is the sequence of code values of the contained wide characters, in order.
...
- The type of each element of a string literal.
- Used for character data from a limited character set (where signedness has little meaning) as opposed to integer data.
wide characters wchar_t
- Used for natural-language character data.
int
- Used for data that could be either
EOF
(a negative value) or character data interpreted asunsigned char
and then converted toint
. ThereforeAs a result, returned byfgetc()
,getc()
,getchar()
, andungetc()
. Also, accepted by the character handling functions from<ctype.h>
, because they might be passed the result offgetc()
et al, etc. - The type of a character constant. Its value is that of a plain
char
converted toint
.
...
Understanding how to represent characters and character strings can eliminate many common programming errors that lead to software vulnerabilities.
...