c language base ---- string

In the C language, using the string actually  null  character '\ 0' one-dimensional array of characters terminated. Therefore, a null-terminated string that contains the character string.

The following statements create and initialize a "Hello" string. Since the end of the array of stores null character, so more than one size of the array of characters than the number of characters in the word "Hello" is.

char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};

According to the array initialization rules, you can put the above statement the following written statement:

char greeting[] = "Hello";

Manipulate strings:

1, strcpy (s1, s2) ;
copy the string to the string s2 s1.
2, strcat (s1, s2) ;
connection string s1 s2 to the end of the string.
3, strlen (s1);
returns the length of the string of s1.
4, strcmp (s1, s2) ;
If s1 and s2 are the same, then return 0; if s1 <s2 is less than 0 is returned; if s1> s2 is greater than 0 is returned.
5, strchr (s1, ch) ;
position returns a pointer to the first character string s1 first occurring ch.
6, strstr (s1, s2) ;
position returns a pointer to the first string s1 s2 of the first occurrence of the string.

Guess you like

Origin www.cnblogs.com/xuey/p/12205337.html