First, the Knowledge point summary:
1, the input of the string:
(1)
scanf"%s", str);/*input parameter: Character array name, without address character. Encountered a carriage return or a space input end, and automatically input a string of characters and ' s ' into the array*///Example:#include <Stdio.h>intMain () {Charstr[ the]; scanf ("%s", str); printf ("%s", str); return 0;}
(2)
gets (str) /* Enter the input string and ' s ' into the array by entering the end of the return input */ // Example:#include <stdio.h>int main () { char str[]; Gets (str); Puts (str); return 0
2, the string copy, the connection ...:
(1) Copying of Strings: strcpy (STR1,STR2)
(2) connection of strings: strcat (STR1,STR2)
(3) Comparison of strings: strcmp (STR1,STR2)
(4) To find the length of the string: strlen (STR1,STR2)
※ Opening plus #include<string.h>
3, String processing function Summary:
| Function |
Function |
Header file |
| Puts (str) |
Output string |
Stdio.h |
| Gets (str) |
Input string (carriage return interval) |
| strcpy (S1,S2) |
S2→s1 |
String.h |
| strcat (S1,S2) |
S1 "+" s2→s1 |
| strcmp (S1,S2) |
if S1 "= =" S2, the function value =0 If S1 ">" s2, the function value >0 If S1 "<" s2, the function value <0 |
| strlen (str) |
Calculates the valid length of a string without Including ' + ' |
4. Structure:
(1) Structure type: The structure type is the data type that aggregates some data components into a whole. Each of these data components has a name.
(2) The general form of the definition is:
struct struct Name {
Type name struct member name 1;
Type name struct member name 2;
Type name struct member name 3;
...
Type name struct member name N;
}
※ The keyword struct is combined with the struct name that follows it to form a new data type name. The definition of a struct ends with a semicolon, because the definition of a struct is treated as a statement in the C language.
5, the structure of the nested definition:
math Street
| study number |
name |
communication address |
< Span style= "font-family: italics; Font-size:14pt "> computer |
English | TD rowspan= "2" >
average result |
| City | Td>
house number |
zip code |
structaddress{Charcity[Ten]; Charstreet[ -];/*defining the address structure*/ intCode; intzip;};structnest_student{intnum; Charname[Ten]; structAddress addr;/*Define communication Address members*/ intComputer,english,math; Doubleaverage;};/* When you define a nested struct type, you must define the structure type of the member, and then define the main structure type * /
6, the definition and initialization of structural variables:
(1) individually defined:
A separate definition refers to defining a struct type and then defining a variable of that type of struct. (the keyword struct and struct name must be used in conjunction to represent a data type name).
(2) Mixed definition:
A hybrid definition defines a structure variable while defining a struct type.
The general form is:
struct struct name {
type name struct member name 1;
type name struct member name 2;
type name struct member name 3;
... ..
type name struct member name N;
} structure variable name table;
(3) No type name definition:
Untyped name definition refers to omitting a struct name when defining a struct variable.
The general form is:
struct {
type name struct member name 1;
type name struct member name 2;
type name struct member name 3;
... ..
type name struct member name N;
} structure variable name table;
※ Since the structure name is omitted, other structural variables of this type cannot be defined after this definition statement (unless the definition process is written again)
struct variables can also be initialized, that is, they are assigned an initial value in the definition. For example:
struct student s1={101,"Zhang", ;
Second, the experimental process encountered problems and solutions:
In this experiment did not encounter any problems, learning the structure of the sentence, but also more practice.
Third, the experimental experience:
The first semester near the end, this is also the last homework, learning a semester of C language feeling or to rely on their own constantly modify the code slowly try to really understand the idea, in peacetime also more practice, proficiency in various ideas, continue to refuel!
Job 12 Summary