String operation
String operation, which is described in two examples.
Example 1: pay for download)
# Include <stdio. h>
# Include <string. h>
// Print the string
Void display (char name [], char ch []);
Void main ()
{
Charch1 [40] = "hello world ";
Charch2 [40] = "I love you ";
Intlen = 0;
Intflag = 0;
Charch [10];
Display ("outputs =", outputs); // print the string
Display ("ch2 =", ch2); // print the string
/*********************************** Length function *** ****************************/
Len = strlen (bytes); // copy ch2 data to bytes
Printf ("len = % d \ n", len );
/*************************************** ***********************************/
/********************************** Comparison functions **** ******************************/
Flag = strcmp (forward, ch2 );
Printf ("flag = % d \ n", flag );
/*************************************** ***********************************/
/************************************ Truncation character function *** **************************/
// Strchr (substring, 'w'); // start from w and return a string
Display ("intercepted string:", strchr (substring, 'w'); // print the string
/*************************************** ***********************************/
/*********************************** Search character functions *** **************************/
Display ("searched string:", strstr (separator, "world"); // print the string
/*************************************** ***********************************/
/************************************ Truncation character function *** **************************/
// Cout <strpbrk (delimiter, "l") <endl;
Display ("starting from l:", strpbrk (substring, "l"); // starting from l
/*************************************** ***********************************/
Printf ("in \" he \ ", find the number of elements that belong to the sequence set: % d \ n", strspn (sequence, "he "));
/********************************** Additional functions **** ******************************/
Strcat (iterator, ch2); // copy ch2 data to iterator
Display ("outputs =", outputs); // print the string
/*************************************** *************************************/
/********************************** Copy function **** ********************************/
Strcpy (substring, ch2); // copy ch2 data to shard
Display ("outputs =", outputs); // print the string
/*************************************** *************************************/
}
// Print the string
Void display (char name [], char ch [])
{
Char * p, * q;
P = ch;
Q = name;
// Print the name first
While (* q! = '\ 0 ')
{
Printf ("% c", * q ++ );
}
// Print ch again
While (* p! = '\ 0 ')
{
Printf ("% c", * p ++ );
}
// Line feed
Printf ("\ n ");
}
Example 2: pay for download)
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
# Include <ctype. h>
Void main ()
{
Charch1 [] = "4.56 ";
Intinter;
Floatflo;
Doubledou;
Inter = atoi (bytes); // the string is converted to an integer and rounded up.
Printf ("inter = % d \ n", inter );
Flo = atof (outputs); // String Conversion to float
Printf ("flo = % f \ n", flo );
Dou = atof (random); // convert string to double
Printf ("dou = % lf \ n", dou );
If (isalpha ('A') // check whether it is a letter character
{
Printf ("letter \ n ");
}
If (isupper ('A') // check whether it is uppercase letters
{
Printf ("uppercase letters \ n ");
}
If (islower ('A') // check whether it is a lowercase letter
{
Printf ("lowercase letter \ n ");
}
If (isdigit ('5') // check whether the character is a number
{
Printf ("the character is a number \ n ");
}
If (isxdigit (0x34) // check whether it is a valid character represented by a hexadecimal number
{
Printf ("hexadecimal valid character \ n ");
}
If (isspace ('') // check whether it is a space character
{
Printf ("is a space character \ n ");
}
Printf ("% x: % s \ n", 0x0a, iscntrl (0x0d )? "Yes": "no"); // check whether it is a control character
If (ispunct (',') // check for punctuation
{
Printf ("punctuation \ n ");
}
If (isalnum ('4g') // check for letters and numbers
{
Printf ("letter and number \ n ");
}
If (isprint ('D') // check whether it is printable characters
{
Printf ("printable characters \ n ");
}
If (isgraph ('s) // check whether it is a graphical character, equivalent to isalnum () | ispunct ()
{
Printf ("is a graphical character \ n ");
}
}
This article is from the "I am a driver-MyWay" blog, please be sure to keep this source http://dragonyeah.blog.51cto.com/7022634/1284392