Comparison between wide character processing functions and common functions
Character classification: Description of common C functions of wide character Functions
Iswalnum () isalnum () test whether the character is a number or letter
Iswalpha () isalpha () test whether the character is a letter
Iswcntrl () iscntrl () test whether the character is a controller
Iswdigit () isdigit () test whether the character is a number
Iswgraph () isgraph () test whether the character is visible
Iswlower () islower () test whether the character is a lowercase character
Iswprint () isprint () test whether the character is printable
Iswpunct () ispunct () test whether the character is a punctuation mark
Iswspace () isspace () test whether the character is a blank sign
Iswupper () isupper () test whether the character is an uppercase character
Iswxdigit () isxdigit () test whether the character is a hexadecimal number
Case sensitivity conversion:
Description of common C functions of wide character Functions
Towlower () tolower () converts characters to lowercase letters
Towupper () toupper () converts the character to uppercase
Character comparison: Description of common C functions of wide character Functions
Wcscoll () strcoll () Comparison string
Date and Time conversion:
Wide character Function Description
Strftime () sets the format date and time based on the specified string format and locale
Wcsftime () sets the format date and time based on the specified string format and locale, and returns the wide string
Strptime () converts a string to a time value based on the specified format, which is the reverse process of strftime.
Print and scan strings:
Wide character Function Description
Fprintf () / Fwprintf () format the output using the vararg Parameter
Fscanf () / Fwscanf () format read
Printf () uses the vararg parameter to format the output to the standard output.
Scanf () reads formatted data from standard input
Sprintf () / Swprintf () is formatted as a string based on the vararg parameter table
Sscanf () is formatted and read as a string
Vfprintf () / Vfwprintf () format the output to a file using the stdarg parameter table
Vprintf () uses the stdarg parameter table to format the output to the standard output.
Vsprintf () / Vswprintf () format the stdarg parameter table and write it to the string
Digital Conversion:
Description of common C functions of wide character Functions
Wcstod () strtodd () converts the initial part of a wide character to a double-precision floating point number.
Wcstol () strtol () converts the initial part of a wide character to a long integer.
Wcstoul () strtoul () converts the initial part of a wide character to an unsigned long integer.
Multi-Byte Character and wide character conversion and operations:
Wide character Function Description
Mblen () determines the number of characters in bytes based on locale settings
Mbstowcs () converts a multi-byte string to a wide string.
Mbtowc () / Btowc () converts a multi-byte character to a wide character
Wcstombs () converts a wide string to a multi-byte string.
Wctomb () / Wctob () converts a wide character to a multi-Byte Character
Input and Output:
Description of common C functions of wide character Functions
Fgetwc () fgetc () reads a character from the stream and converts it to a wide character.
Fgetws () fgets () reads a string from the stream and converts it to a wide string.
Fputwc () fputc () converts wide characters into multi-byte characters and outputs them to standard output.
Fputws () fputs () converts a wide string into multiple bytes and outputs the string to the standard output string.
Getwc () GETC () reads characters from the standard input and converts them to wide characters.
Getwchar () getchar () reads characters from the standard input and converts them to wide characters.
None gets () Use fgetws ()
Putwc () putc () converts a wide character into a multi-Byte Character and writes it to the standard output.
Putwchar () putchar () converts a wide character into a multi-Byte Character and writes it to the standard output.
None puts () Use fputws ()
Ungetwc () ungetc () places a wide character in the input stream
String operation:
Description of common C functions of wide character Functions
Wcscat () strcat () concatenates a string to the end of another string
Wcsncat () strncat () is similar to wcscat () and specifies the bond length of the bond string.
Wcschr () strchr () finds the first position of the substring
Wcsrchr () strrchr () searches for the first position of the substring from the tail.
Wcspbrk () strpbrk () Searches from the character string for the first occurrence of any character in the other string
Wcswcs () / Wcsstr () strchr () searches for the position where another string appears for the first time in a string.
Returns the initial number of records that do not contain the second string.
Wcsspns () strspns () returns the initial number of strings containing the second string.
Wcscpy () strcpy () Copy string
Wcsncpy () strncpy () is similar to wcscpy () and specifies the number of copies.
Wcscmp () strcmp () compares two wide strings
Wcsncmp () strncmp () is similar to wcscmp () and also specifies the number of character strings to be compared.
Wcslen () strlen () gets the number of wide strings
Wcstok () strtok () Splits a wide string into a series of strings Based on the identifier
Wcswidth () None to get the width of the wide string
Wcwidth () None
In addition, wmemcpy (), wmemchr (), wmemcmp (), wmemmove (), and wmemset () for memory operations ().
In addition:
Function Name: stpcpy
Function: copy one string to another.
Usage: char * stpcpy (char * Destin, char * Source );
ProgramExample:
# Include <stdio. h>
# Include <string. h>
Int main (void)
{
Char string [10];
Char * str1 = "abcdefghi ";
Stpcpy (string, str1 );
Printf ("% s \ n", string );
Return 0;
}
Function Name: strcat
Function: String concatenation Function
Usage: char * strcat (char * Destin, char * Source );
Program example:
# Include <string. h>
# Include <stdio. h>
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 matching position of a given character in a string \
Usage: char * strchr (char * STR, char C );
Program example:
# Include <string. h>
# Include <stdio. h>
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
Function: String comparison
Usage: int strcmp (char * str1, char * str2 );
View ASIC code, str1> str2, return value> 0; two strings are equal, return 0
Program example:
# Include <string. h>
# Include <stdio. h>
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
Function: compares a part of a string with another string regardless of case.
Usage: int strncmpi (char * str1, char * str2, unsigned maxlen );
Program example:
# Include <string. h>
# Include <stdio. h>
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: Copy strings
Usage: char * strcpy (char * str1, char * str2 );
Program example:
# Include <stdio. h>
# Include <string. h>
Int main (void)
{
Char string [10];
Char * str1 = "abcdefghi ";
Strcpy (string, str1 );
Printf ("% s \ n", string );
Return 0;
}
Function Name: strcspns
Function: Search for the content segment of the first given character set in the string.
Usage: int strcspn (char * str1, char * str2 );
Program example:
# Include <stdio. h>
# Include <string. h>
# Include <alloc. h>
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 position.
Usage: char * strdup (char * Str );
Program example:
# Include <stdio. h>
# Include <string. h>
# Include <alloc. h>
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: Compares two strings in upper and lower case insensitive mode.
Usage: int stricmp (char * str1, char * str2 );
Program example:
# Include <string. h>
# Include <stdio. h>
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
Function: returns a pointer to the error message string.
Usage: char * strerror (INT errnum );
Program example:
# Include <stdio. h>
# Include <errno. h>
Int main (void)
{
Char * buffer;
Buffer = strerror (errno );
Printf ("error: % s \ n", buffer );
Return 0;
}
Function Name: strcmpi
Function: compares a string with another string, regardless of case.
Usage: int strcmpi (char * str1, char * str2 );
Program example:
# Include <string. h>
# Include <stdio. h>
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
Function: String comparison
Usage: int strncmp (char * str1, char * str2, int maxlen );
Program example:
# Include <string. h>
# Include <stdio. h>
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
Function: compares a part of a string with a part of another string, regardless of case.
Usage: int strncmpi (char * str1, char * str2 );
Program example:
# Include <string. h>
# Include <stdio. h>
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
Function: Copy strings
Usage: char * strncpy (char * Destin, char * Source, int maxlen );
Program example:
# Include <stdio. h>
# Include <string. h>
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
Function: Compares two strings case-insensitive.
Usage: int strnicmp (char * str1, char * str2, unsigned maxlen );
Program example:
# Include <string. h>
# Include <stdio. h>
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 a specified character.
Usage: char * strnset (char * STR, char CH, unsigned N );
Program example:
# Include <stdio. h>
# Include <string. h>
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: searches for characters in a given character set in a string.
Usage: char * strpbrk (char * str1, char * str2 );
Program example:
# Include <stdio. h>
# Include <string. h>
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 a specified character in the string.
Usage: char * strrchr (char * STR, char C );
Program example:
# Include <string. h>
# Include <stdio. h>
Int main (void)
{
Char string [15];
Char * PTR, c = 'R ';
Strcpy (string, "This is a string ");
PTR = strrchr (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
Power: String reversal
Usage: char * strrev (char * Str );
Program example:
# Include <string. h>
# Include <stdio. h>
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 a specified character.
Usage: char * strset (char * STR, char C );
Program example:
# Include <stdio. h>
# Include <string. h>
Int main (void)
{
Char string [10] = "123456789 ";
Char symbol = 'C ';
Printf ("before strset (): % s \ n", string );
Strset (string, symbol );
Printf ("after strset (): % s \ n", string );
Return 0;
}
Function Name: strspns
Function: finds the first occurrence of a subset of a specified character set in a string.
Usage: int strspn (char * str1, char * str2 );
Program example:
# Include <stdio. h>
# Include <string. h>
# Include <alloc. h>
Int main (void)
{
Char * string1 = "1234567890 ";
Char * string2 = "123dc8 ";
Int length;
Length = strspns (string1, string2 );
Printf ("character where strings differ is at position % d \ n", length );
Return 0;
}
Function Name: strstr
Function: Search for the first appearance of a specified string in the string.
Usage: char * strstr (char * str1, char * str2 );
Program example:
# Include <stdio. h>
# Include <string. h>
Int main (void)
{
Char * str1 = "Borland International", * str2 = "nation", * PTR;
PTR = strstr (str1, str2 );
Printf ("the substring is: % s \ n", PTR );
Return 0;
}
Function Name: strtodd
Function: converts a string to a double value.
Usage: Double strtodd (char * STR, char ** endptr );
Program example:
# Include <stdio. h>
# Include <stdlib. h>
Int main (void)
{
Char input [80], * endptr;
Double value;
Printf ("enter a floating point number :");
Gets (input );
Value = strtodd (input, & endptr );
Printf ("the string is % s the number is % lf \ n", input, value );
Return 0;
}
Function Name: strtok
Function: searches for words separated by the delimiters specified in the second string.
Usage: char * strtok (char * str1, char * str2 );
Program example:
# Include <string. h>
# Include <stdio. h>
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
To the character following the token */
P = strtok (null ,",");
If (p) printf ("% s \ n", P );
Return 0;
}
Function Name: strtol
Function: converts a string to a long integer.
Usage: Long strtol (char * STR, char ** endptr, int base );
Program example:
# Include <stdlib. h>
# Include <stdio. h>
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 a string to uppercase letters.
Usage: char * strupr (char * Str );
Program example:
# Include <stdio. h>
# Include <string. h>
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
Function: swap byte
Usage: void swab (char * From, char * To, int nbytes );
Program example:
# Include <stdlib. h>
# Include <stdio. h>
# Include <string. h>
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;
}
I ran this in an EVC simulator.
Lpwstr szpathprefix, S;
Tchar szpath [max_path];
Getmodulefilename (null, szpath, max_path );
Szpathprefix = szpath;
S = wcsrchr (szpathprefix, L '\\');
Drawtext (HDC, S, _ tcslen (s), & RT,
Dt_singleline | dt_vcenter | dt_center );
The result is \ testevc3.exe.
It seems to be changed from the previous figure.