Some strings and character functions in C language, string character Functions
//// Main. c // homeWork1230 //// # include <stdio. h> # include <string. h> # include <ctype. h> int main (int argc, const char * argv []) {// strstr (str1, str2) function is used to determine whether str2 is a substring of str1. If yes, the function returns the address str2 first appeared in str1; otherwise, NULL is returned. // Printf ("% s \ n", strstr ("Chinaisgood", "is"); // compare the string Size Based on ASCII. // Printf ("% d \ n", strcoll ("Chinaisgood", "As");/* Function Description: strcspn () calculate consecutive characters from the beginning of the parameter s string, and these characters are not included in the string referred to by the parameter reject. to put it simply, if the value returned by strcspns () is n, it indicates that n consecutive characters starting with string s do not contain any character in string reject. * // printf ("% lu \ n", strcspn ("Chinais good", "in"); // each of them is used to locate a character in the string, strstr the other is to locate a string in another string. // Printf ("% s \ n", strchr ("abcdefghijklmnopqrstuvwxyz", 'C'); // copy // char * B; // B = strdup ("afnksf"); // printf ("% s \ n", B); // s1, when s2 is a string, memcmp (s1, s2, 1) Compare the ascII value of the first byte of s1 and s2; // printf ("% d \ n", memcmp ("avc", "dds ", 1); // It is used to find the c string needle in the c string haystack, regardless of the case. If yes, the char pointer // printf ("% s \ n", strcasestr ("fFDsafds", "d") at the first position of the needle string in the haystack string is returned ")); // you can see what this function is for. In most operating systems, this function is not implemented. // The strnstr function is described. Search for s2 in the first pos1 string of s1, if yes, the position of s2 in s1 is returned. If no value is found, NULL is returned. The test is normal. // printf ("% s \ n", strnstr ("abcd ", "c", 2); // copy // char * s = "Golden Global View"; // char d [20]; ///// clrscr (); // stpcpy (d, s); // printf ("% s \ n", d); // copy, only to nth // char * s = "Golden Global View"; // char d [20]; // Strlcpy (d, s, 6); // printf ("% s \ n", d ); // character function // determines whether the character variable c is a letter or number. If yes, the return value is non-zero. Otherwise, the return value is zero. // printf ("% d \ n ", isalnum ('$'); // used to determine whether a character is a TAB or space. If yes, the return value is non-zero. Otherwise, the return value is zero. // printf ("% d \ n ", isblank (''); // function: determines whether the character c is a control character. // Description: if the character c is between 0x00-0x1F or equal to 0x7F (DEL), a non-zero value is returned, otherwise, zero is returned. // Printf ("% d \ n", iscntrl ('\ n'); // determines whether it is a printable character // printf ("% d \ n ", isgraph ('$'); // determines whether it is a punctuation mark // printf ("% d \ n", ispunct ('A ')); // check whether parameter c is a space character, that is, whether it is a space ('') or a horizontal positioning character. // ('\ t '), Return key ('\ R'), line feed (' \ n'), vertical positioning character ('\ V'), or flip (' \ F ') // printf ("% d \ n", isspace ('A'); // convert the character to an ascii value // printf ("% d \ n ", toascii ('A'); // converts the character number to an integer // printf ("% d \ n", digittoint ('9 ')); // determine whether a character is a number. // printf ("% d \ n", isnumber ('4'); // determine whether a character is between 0 and 127, whether it is ascii // printf ("% d \ n", isascii ('000000'); return 0 ;}