- String and character pointers
string constant "array", "point"
A sequence of characters enclosed in a pair of double quotes
is seen as a special one-dimensional array of characters that are stored in memory continuously
is essentially a pointer constant pointing to the first character of the string
- Char sa[]= "Array";
Char *sp= "point";
Printf ("%s", SA);
Printf ("%s", SP);
Printf ("%s\n" "string");
The value of the array name SA, the pointer sp, and the string "string" are all addresses.
- Char sa[]= "This is a string";
Char *sp= "This is a string";
If you want to change the string represented by the array SA, you can only change the contents of the array element.
If you want to change the string that the pointer sp represents, you usually change the pointer's value directly so that she points to the new character.
- Common String Handling functions
- Function prototypes are given in stdio.h or string.h
Input and output of strings
Input string: scanf () or gets ()
Output string: printf () or puts ()
Stdio.h
- SCANF ("%s", str)
Input parameters: Character array name, without address character
Enter the end of a carriage return or a space, and automatically input a string of characters and ' s ' into the array
- String copy, concatenate, compare, string length
String copy Strpy (STR1,STR2)
String Connection strcat (STR1,STR2)
string comparison strcmp (STR1,STR2)
String length strlen (str)
String.h
- string comparison strcmp (STR1,STR2)
Compare the size of two strings
Rules: by Dictionary (ASCII code order)
If str1 and str2 are equal, return 0
If STR1 is greater than str2, returns a positive integer
Returns a negative integer if str1 is less than str2
Summary of the 12th time assignment