Home > database >  notes
notes

Time:09-29

1, 1) character array input and output % s2) character array initialization string char ch []="hello" 2, string handling functions (1) prototype function return value function name (parameter 1 type parameters, parameter type parameter 2... 2) function call syntax function name (argument 1, argument 2... ) indicates that: the argument must have a certain value, and the number and parameters, types and parameters are consistent or compatible assignment int a=3.6, double x=3; 1, the string input, output function int gets (char * STR)====from the keyboard input a string, int the save to STR points to a location in memory puts (char * STR)=====output at the address of the string STR, and newlines char ch [20]; Gets (ch); <==> Gets (& amp; Ch [0]) gets (ch [1]) error, the argument type is char, and the function gets the required parameter type for char * gets (& amp; Ch [1]), right from the keyboard input a string, save the array elements from ch [1] puts (ch); Puts (& amp; Ch [1]); Correct, the output from ch [1] a string (string) to the \ 0 before puts (" hello "); 2, char * string concatenation function strcat (char * str1, char * str2) will be pointed out by str2 string, connected to the strings str1 points to the back, behind and remove st1\0, returns the str1 (address) (note that the str1 points to the memory unit is large enough (after put down the connection string) char ch1 []="hello"; Char ch2 []="world"; Strcat (ch1 and ch2); Error, ch1 is not big enough char ch1 [20]="hello"; Char ch2 []="world"; Strcat (ch1 and ch2); Correct puts (ch1); Output helloworldputs (strcat (ch1 and ch2)); Strcat (ch1 and ch2) the result of the function call (the function return value) as the arguments of the puts, calls right, output??? Strcat (ch1, & amp; Ch2 [3]); Puts (ch1); Output helloldputs (strcat (ch1, & amp; Ch2 [3])); Output?????? Strcat (& amp; Ch1 [2], ch2); Puts (ch1); Output the helloworld??????? Puts (strcat (& amp; Ch1 [2], ch2)); Output??????? 3, char * string copy function 1) function prototype strcpy (char * str1, char * str2) copy str2 string points to to the memory unit, the str1 points to return str1 (address) (note that the str1 points to memory cell size to be greater than or equal to the str2 points to the memory unit size char ch1 [20]="hello"; Char ch2 []="wor"; Strcpy (ch1 and ch2); Puts (ch1); Output worstrcpy (" hello ", "worldddd"); Error, the first parameter of memory space is not large enough puts (strcpy (ch1 and ch2)); Output worstrcpy (& amp; Ch1 [1], & amp; Ch2 [1]). Puts (ch1); Output horputs (strcpy (& amp; Ch1 [1], & amp; Ch2) [1]) output or equivalent to strcpy (& amp; Ch1 [1], & amp; Ch2 [1]). Puts (& amp; Ch1 [1]). 2) the function prototype char * strncpy (char * str1, char * str2, int n); The str2, pointing to the n of the characters (not necessarily include \ 0), copied to the str1 points to a location in memory returned str1 char (address) ch1 [20]="hello"; Char ch2 []="world"; Strncpy (ch1 and ch2, 3); Puts (ch1);//output worlo4, string comparison function function prototype int STRCMP (char * str1, char * str2) to compare the size of the two strings (the size of each character is ASCII value), if the str1 & gt; Str2 returns 1, if the str1=str2 returns 0, if str1 & lt; Str2 returned to 15, the effective length of the string function prototype unsigned int strlen (char * STR) statistical STR the number of characters in the string, not including \ 0, returns the number character char ch1 [20]="hello"; Char ch2 []="world"; Int a, b, c; A=strlen (ch1); 5 b=strlen (ch2); 5 c=strlen (" wordl "); 56, string into lowercase STRLWR (char * STR) char ch1 []="Hello" STRLWR (ch1)//hello7, string converted to uppercase strupr (char * STR) char ch1 []="Hello" strupr (ch1);//HELLO chapter 7 function (achieved a certain function code modules) - modular, code reuse 1, the definition of the function, grammar function return value type function name (parameter 1 type parameters, parameter type parameter 2... )//function first {//the body of the function, the realization of the function of function} : the function return value types, namely function types, after completion of the return value is a function of the type, if not, clearly defined as void, if there is a return value, want to use the return statement in the function body back to the return value function called any legal identifier parameter: the function complete function, the necessary conditions of known without parentheses what also don't write, is called a no-parameter function (such as the line of 1-100) and is no function function body: with the content of the big parentheses, is the complete implementation of function function, for example, write a function, two integers and int the add (int x, int y) {int z=x + y; Return the z; } int f=add (2, 3); Int the add () {int x, y, z; The scanf (" % d % d ", & amp; X, & amp; Y); z=x+y; Return the z; } int f=add ();