Char In C
Có thể bạn quan tâm
Characters in C
char
In C, char values are stored in 1 byte, and are encoded as numbers using the ASCII encoding.The man page for ascii lists all the encodings: % man ascii
You should never use the ASCII numeric value directly, but you should know that the characters 'A' to 'Z' are contiguous, 'a' to 'z' are contiguous, and '0' to '9' are contigouous. Using the relationships between the upper case alphabetic, the lower case alphabetic, and the numeric characters I can write expressions like this: char ch; 'a' + 2 // evaluates to the character value 'c' (becuase 'a' is // (encoded as a number we can add 2 to it to get 'c') 'C' > 'A' // evaluates to true, which is a non-zero value in C // (0 is false) for(ch = 'a'; ch < 'z'; ch++) { ... ch = getchar(); // read in a char value from stdin printf("ch is %c\n", ch);
C library functions for characters
The Standard C library has functions you can use for manipulating and testing character values: #include <ctype.h> int islower(ch); int isupper(ch); // these functions return a non-zero value if the int isalpha(ch); // test is TRUE, otherwise they return 0 (FALSE) int isdigit(ch); int isalnum(ch); int ispunct(ch); int isspace(ch); char tolower(ch); char toupper(ch); Here are some examples of what they do/return: char c = toupper('a'); // returns the character value 'A' islower('Z') // returns 0 (FALSE) isspace(ch) // returns non-zero (TRUE) if ch is a whitespace character // ' ', '\t', '\n', '\r', '\f', or '\v'
Từ khóa » C Char
-
Working With Character (char) In C - OpenGenus IQ
-
C - Strings - Tutorialspoint
-
Strings In C (With Examples) - Programiz
-
C Character Type - Learn C Programming From Scratch
-
What's Difference Between Char S[] And Char *s In C? - GeeksforGeeks
-
Unsigned Char In C With Examples - GeeksforGeeks
-
ASCII Table
-
What Is Char ** In C? [duplicate] - Stack Overflow
-
C Programming Tutorial 25 - Char Data Type - YouTube
-
C Char Data Type - C Programming
-
How To Play With Strings In C - Coding Game
-
C Keywords: Char
-
Character Constant