A char* is not an array or strings, it's a pointer to a char. Strings in C are just a pointer to a char where subsequent addresses in memory contain the nect characters of the string. In the case of the str* functions in the standard C library, and in many other places according to convention, the string ends when a \0 (ASCII NUL) character is found. The programmer is responsible for memory management with such strings.
An "array of strings" in C is a pointer to a pointer to a char, like argv (type = char**). Normally the programmer must allocate memory for the array of pointers, and also allocate memory for each string which is pointed to.
Enter the STL string class... It's all fine, but it gets ugly when youo want to mix it with old C style strings. There is a member of the class, c_str() which returns char* (don't free() this!). If you want to modify this, you should allocate for your own char*, and copy it with strcpy().
|