We already know that string constants are character sequences enclosed by double quotation marks, for example:
"A string"
It is a String constant. Because character a is followed by a space character, it is composed of eight character sequences. If a String constant C Compilation Program appears in a program, a storage area is arranged for the String constant. This area is static and is always occupied during the entire program running, the length of a String constant is the number of characters in the string, the C compiler automatically adds an empty character '''' to the end of the string sequence to mark the end of the string, therefore, the number of bytes in the storage area occupied by a String constant is one more byte than the number of its characters.
The methods for operating a String constant in Turbo C include:
(1). Store string constants in a character array, for example:
Char s [] = "a string ";
The array s consists of nine elements. The content in s [8] Is ''''. In fact, during the definition of the character array, the compiler directly rewrites the string to the array, that is, initializing the array s.
(2). Use a character pointer to point to a string, and then use a character pointer to access the string storage area. When a String constant appears in an expression, it is converted to a character pointer according to the type conversion rules of the array. Therefore, if we define a one-character pointer cp:
Char * cp;
So available:
Cp = "a string ";
Point cp to character a, 7, of the String constant.
Cp
When there are too many threads, there are too many threads, too many threads.
When-then-→ when a packet has seconds t been r He I have n Gbit/s then
When there are too many threads, there are too many threads, too many threads.
Figure 7.
In the future, we can access this storage area through cp. For example, * cp or cp [0] Is Character a, and cp [I] Or * (cp + I) it is equivalent to character I of a string, but it does not make sense to attempt to modify a String constant through a pointer.
Lieti
[Program 96]
Question: calculate the number of times a string neutron string appears
1. program analysis:
2. program source code:
# Include "string. h"
# Include "stdio. h"
Main ()
{Char str1 [20], str2 [20], * p1, * p2;
Int sum = 0;
Printf ("please input two stringsn ");
Scanf ("% s", str1, str2 );
P1 = str1; p2 = str2;
While (* p1! = '''')
{
If (* p1 = * p2)
{While (* p1 = * p2 & * p2! = '''')
{P1 ++;
P2 ++ ;}
}
Else
P1 ++;
If (* p2 = '''')
Sum ++;
P2 = str2;
}
Printf ("% d", sum );
Getch ();}