C language string function

xiaoxiao2021-03-06  41

Function Name: STPCPY function: copy a string to another: char * stpcpy (char * destin, char * source);

#include #include

INT main (void) {char string [10]; char * str1 = "abcdefghi";

Stpcpy (string, str1); Printf ("% s / n", string; return 0;}

Function Name: STRCAT Energy: String Splicing Function Usage: Char * Strcat (Char * Destin, Char * Source);

#include #include

INT main (void) {char Destination [25]; char * blank = "", * c = "c ", * borland = "borland";

STRCPY (Destination, Borland); STRCAT (DESTINATION, BLANK); STRCAT (DESTINATION, C);

Printf ("% s / n", destination; return 0;}

Function Name: STRCHR Function: Find the first match of given characters in a string / usage: char * str, char c);

#include #include

INT main (void) {char string [15]; char * ptr, c = 'r';

STRCPY (String, "This Is A String"); PTR = STRCHR (String, C); IF (PTR) Printf ("THE Character% C IS At Position:% D / N", C, PTR-String; ELSE Printf ("THE Character Was Not Found / N); Return 0;}

Function Name: STRCMP Features: String Comparison Us: Int strCMP (Char * STR1, CHAR * STR2); Look at the ASIC Code, Str1> STR2, Return Value> 0; Two Strings Equality, Returns 0 Series:

#include #include

INT main (void) {char * buf1 = "aaa", * buf2 = "bbb", * buf3 = "ccc"; int PTR;

PTR = STRCMP (BUF2, BUF1); IF (PTR> 0) Printf ("Buffer 2 Is Greater Than Buffer 1 / N"); Else Printf ("Buffer 2 IS Less Than Buffer 1 / N");

PTR = STRCMP (BUF2, BUF3); IF (PTR> 0) Printf ("Buffer 2 IS Greater Than Buffer 3 / N"); Else Printf ("Buffer 2 IS LESS THAN Buffer 3 / N); Return 0;}

Function Name: Strncmpi Features: Compares part of a string with another string, regardless of case: int strncmpi (char * str1, char * str2, unsigned maxlen);

#include #include

INT main (void) {char * buf1 = "bbb", * buf2 = "bbb"; int PTR;

PTR = Strcmpi (buf2, buf1);

IF (PTR> 0) Printf ("Buffer 2 IS Greater Than Buffer 1 / N");

IF (PTR <0) Printf ("Buffer 2 IS Less Than Buffer 1 / N");

IF (PTR == 0) Printf ("Buffer 2 Equals Buffer 1 / N");

Return 0;}

Function name: STRCPY function: String copy usage: char * strcpy (char * str1, char * str2);

#include #include

INT main (void) {char string [10]; char * str1 = "abcdefghi";

STRCPY (String, Str1); Printf ("% s / n", string; return 0;}

Function Name: STRCSPN function: Find a paragraph usage of the first given character set content in the string: int Strcspn (Char * STR1, CHAR * STR2);

#include #include #include

INT main (void) {char * string1 = "1234567890"; char * string2 = "747dc8"; int LENGTH;

Length = strcspn (string1, string2); Printf ("Character WHERE STRINGS INTERSECT IS AT POSITION% D / N", Length);

Return 0;}

Function Name: STRDUP function: copy the string to the new location: char * strdup (char * STR);

#include #include #include

INT main (void) {char * dup_str, * string = "abcde";

DUP_STR = STRDUP (String); Printf ("% S / N", DUP_STR); Free (DUP_STR);

Return 0;}

Function name: Stricmp function: Two string usage: int Strics (char * str1, char * str2); program example: #include #include

INT main (void) {char * buf1 = "bbb", * buf2 = "bbb"; int PTR;

PTR = Stricmp (buf2, buf1);

IF (PTR> 0) Printf ("Buffer 2 IS Greater Than Buffer 1 / N");

IF (PTR <0) Printf ("Buffer 2 IS Less Than Buffer 1 / N");

IF (PTR == 0) Printf ("Buffer 2 Equals Buffer 1 / N");

Return 0;}

Function Name: STRERROR Energy: Returns a pointer to the error message string: char * strerror (int errnum);

#include #include

INT main (void) {charffer; buffer = strerror (errno); Printf ("Error:% S / N", Buffer; Return 0;}

Function Name: STRCMPI function: Put a string with another, regardless of the case: int strcmpi (char * str1, char * str2);

#include #include

INT main (void) {char * buf1 = "bbb", * buf2 = "bbb"; int PTR;

PTR = Strcmpi (buf2, buf1);

IF (PTR> 0) Printf ("Buffer 2 IS Greater Than Buffer 1 / N");

IF (PTR <0) Printf ("Buffer 2 IS Less Than Buffer 1 / N");

IF (PTR == 0) Printf ("Buffer 2 Equals Buffer 1 / N");

Return 0;}

Function Name: STRNCMP Features: String Comparison Usage: Int StrMP (Char * STR1, CHAR * STR2, INT MAXLEN);

#include #include

Int main (void)

{Char * buf1 = "aaabbb", * buf2 = "bbbccc", * buf3 = "ccc"; int PTR;

PTR = Strncmp (BUF2, BUF1, 3); IF (PTR> 0) Printf ("Buffer 2 IS Greater Than Buffer 1 / N"); Else Printf ("Buffer 2 IS Less Than Buffer 1 / N");

PTR = Strncmp (BUF2, BUF3, 3); IF (PTR> 0) Printf ("Buffer 2 IS Greater Than Buffer 3 / N"); Else Printf ("Buffer 2 IS Less Than Buffer 3 / N); Return ( 0);

Function Name: Strncmpi Features: Compares part of the string with the other string, regardless of case: int strncmpi (char * str1, char * STR2);

#include #include

INT main (void) {char * buf1 = "bbbccc", * buf2 = "bbbccc"; int Ptr;

PTR = Strncmpi (buf2, buf1, 3);

IF (PTR> 0) Printf ("Buffer 2 IS Greater Than Buffer 1 / N");

IF (PTR <0) Printf ("Buffer 2 IS Less Than Buffer 1 / N");

IF (PTR == 0) Printf ("Buffer 2 Equals Buffer 1 / N");

Return 0;}

Function Name: STRNCPY Energy: String copy usage: char * STRNCPY (Char * Destin, Char * Source, int Maxlen);

#include #include

INT main (void) {char string [10]; char * str1 = "abcdefghi";

STRNCPY (String, STR1, 3); String [3] = '/ 0'; Printf ("% S / N", String); Return 0;}

Function Name: Strnicmp Features: Do not pay attention to two string usage: int Strnicmp (Char * STR1, CHAR * STR2, UNSIGNED MAXLEN);

#include #include

INT main (void) {char * buf1 = "bbbccc", * buf2 = "bbbccc"; int Ptr;

PTR = Strnicmp (BUF2, BUF1, 3);

IF (PTR> 0) Printf ("Buffer 2 IS Greater Than Buffer 1 / N");

IF (PTR <0) Printf ("Buffer 2 IS Less Than Buffer 1 / N");

IF (PTR == 0) Printf ("Buffer 2 Equals Buffer 1 / N");

Return 0;}

Function Name: STRNSET Function: Set all characters in a string to specify character usage: char * strnset (char * STR, CHAR CH, UNSIGNED N);

#include #include

INT main (void) {char * string = "abcdefghijklmnopqrstuvwxyz"; char letter = 'x'; Printf ("String Before Strnset:% S / N", String); strnset (String, Letter, 13); Printf ("String After strnset:% s / n ", string);

Return 0;}

Function Name: STRPBRK function: Find a character usage in a set of gauges in a string: char * strpbrk (char * str1, char * str2);

#include #include

INT main (void) {char * string1 = "abcdefghijklmnopqrstuvwxyz"; char * string2 = "onm"; char * PTR;

PTR = strpbrk (string1, string2);

IF (PTR) Printf ("StrPBRK Found First Character:% C / N", * PTR); Else Printf ("StrPBRK Didn't Find Character In Set / N");

Return 0;}

Function Name: STRRCHR Function: Find the last occurrence of the specified character in the string: char * strrchr (char * str, char c);

#include #include

INT main (void) {char string [15]; char * ptr, c = 'r';

STRCPY (String, "This Is A String"); PTR = STRCHR (String, C); IF (PTR) Printf ("THE CHARACTER% C IS At Position:% D / N", C, PTR-String; ELSE Printf ("THE Character Was Not Found / N); Return 0;}

Function Name: StrRev Features: String Usage: Char * Strrev (Char * STR);

#include #include

INT main (void) {char * forward = "string";

Printf ("Before Strrev ():% S / N", Forward); Strrev (Forward); Printf ("After Strrev ():% S / N", Forward); Return 0;}

Function Name: STRSET function: Set all characters in a string to specify character usage: char * str, char c);

#include #include

INT main (void) {char string [10] = "123456789"; char Symbol = 'c';

Printf ("Before StRSET ():% S / N", String); strSet (String, Symbol); Printf ("After strs ():% s / n", string; return 0;} function name: strspn Energy: Find the first appearance method of the subset of the specified character set in the string: int StRSPN (Char * STR1, CHAR * STR2);

#include #include #include

INT main (void) {char * string1 = "1234567890"; char * string2 = "123DC8"; int LENGTH;

Length = strspn (string1, string2); Printf ("Character WHERE STRINGS DIFFER IS AT POSITION% D / N", Length; Return 0;}

Function Name: Strstr Function: Find the first appearance method of specified strings in the string: char * strstr (char * str1, char * str2);

#include #include

INT main (void) {char * str1 = "borland International", * str2 = "nation", * ptr;

PTR = strs (str1, str2); Printf ("The Substring IS:% S / N", PTR); Return 0;}

Function Name: STRTOD function: convert a string to Double type value: Double Strtod (Char * STR, Char ** Endptr);

#include #include

Int main (void) {char INPUT [80], * endptr; Double Value;

Printf ("Enter A Floating Point Number:"); Gets (Input); Value = Strtod (Input, & Endptr); Printf ("THE STRING IS% S THE NUMBER IS% LF / N", Input, Value); Return 0 }

Function Name: STRTOK function: Find a word usage separated by the divided division in the second string: char * str1, char * STR2);

#include #include

INT main (void) {char input [16] = "ABC, D"; char * p;

/ * STRTOK Places A Null Terminator In Front of the Token, if Found * / P = Strtok (Input, ","); if (p) Printf ("% s / n", p);

/ * A Second Call to Strtok Using A NULL As The First Parameter Returns a Pointer token * / P = Strtok (NULL, ","); if (p) printf ("% s / n", P ); RETURN 0;} function name: STRTOL function: convert the string to long integer usage: long strtol (char * str, char ** endptr, int base);

#include #include

INT main (void) {char * string = "87654321", * endptr; long lnumber;

/ * STRTOL Converts String to long integer * / lnumber = strtol (string, & endptr, 10); Printf ("string =% s long =% ld / n", string, lnumber;

Return 0;}

Function name: STRUPR function: converts lowercase letters in the string to uppercase letters usage: char * strupr (char * STR);

#include #include

INT main (void) {char * string = "AbcdefghijklmnopqrStuvwxyz", * Ptr;

/ * Converts String to Upper Case Characters * / PTR = Strupr (String); Printf ("% S / N", PTR); return 0;}

Function Name: SWAB Features: Switch byte Usage: Void Swab (Char * from, Char * To, INT NBYTES);

#include #include #include

Char source [15] = "RFNA KoblRNA D"; Char Target [15];

INT main (void) {swab (Source, Target, Strlen (Source)); Printf ("this is target:% s / n", target); return 0;}

转载请注明原文地址:https://www.9cbs.com/read-51785.html

New Post(0)