Character Array in C
◀ String▶ C++ String Class Amazon
First of all, the concept of a string in C is always a character array. Standard C++ STL, however, includes the
string class that provides common manipulations of a character array.
A
char array is simply an array of
char. Here is an example of how to use
malloc() to create a three-dimensional
char array:
char ***peers;
peers=(char***)malloc(3*sizeof(char**)); /* peers contains 3 char** */
peers[0]=(char**)malloc(3*sizeof(char*)); /* peers[0] contains 3 char* */
peers[1]=(char**)malloc(4*sizeof(char*)); /* peers[1] contains 4 char* */
peers[2]=(char**)malloc(5*sizeof(char*)); /* peers[2] contains 5 char* */
/* initialize all char* variables, 12 total */
peers[0][0]="guys";
peers[0][1]="it";
peers[0][2]="all";
peers[1][0]="comes";
peers[1][1]="down";
peers[1][2]="to";
peers[1][3]="dealing";
peers[2][0]="with";
peers[2][1]="people";
peers[2][2]="david";
peers[2][3]="and";
peers[2][4]="jim";
This chapter will introduce you to many common functions that you can use to manipulate a
string, which is guaranteed to prove useful in your programming career!
◀ String▶ C++ String Class