C Programming Language Tutorial
Variables and Data Types
Input/Output
Looping and Selection Structures
Array
Functions
Preprocessing Command
Pointer
Structure
File Operations
Important Knowledge
" "
, such as "http://www.iditect.com"
, "iditect"
. The characters in the string are arranged in order and next to each other in the memory, and the entire string occupies a contiguous piece of memory. "A"
, "6"
; but for the convenience of operation, we generally use a special character type to deal with. ' '
and strings are surrounded by double quotes " "
. //correct spelling char a = '1'; char b = '$'; char c = 'X'; char d = ' '; // space is also a character // wrong spelling char x = '그'; //char type cannot contain characters other than ASCII encoding char y = 'A'; //A is a full-width character char z = "t"; //Character type should be surrounded by single quotesNote: In the character set, the numbers (or encoding values) corresponding to full-width characters and half-width characters are different, and they are two characters; ASCII encoding only defines half-width characters, not full-width characters.
%c
.#include <stdio.h> int main() { char a = '1'; char b = '$'; char c = 'X'; char d = ' '; // use putchar output putchar(a); putchar(d); putchar(b); putchar(d); putchar(c); putchar('\n'); // use printf output printf("%c %c %c\n", a, b, c); return 0; }Running result:
#include <stdio.h> int main() { char a = 'E'; char b = 70; int c = 71; int d = 'H'; printf("a: %c, %d\n", a, a); printf("b: %c, %d\n", b, b); printf("c: %c, %d\n", c, c); printf("d: %c, %d\n", d, d); return 0; }Output result:
char str1[] = "http://www.iditect.com"; char *str2 = "iditect";str1 and str2 are the names of strings, and the following
[ ]
and the preceding *
are fixed. Beginners can temporarily think that these two storage methods are equivalent, and they can be output through the dedicated puts function and the general printf function. #include <stdio.h> int main() { char web_url[] = "http://www.iditect.com"; char *web_name = "iditect"; puts(web_url); puts(web_name); printf("%s\n%s\n", web_url, web_name); return 0; }
ASCII encoding and representation of English characters in C:
#include <stdio.h> // ASCII encoding and representation of English characters in C int main() { char englishChar = 'A'; printf("ASCII Value of %c: %d\n", englishChar, (int)englishChar); return 0; }
Printing English characters using printf in C language:
%c
format specifier in printf
is used to print English characters.#include <stdio.h> // Printing English characters using printf in C int main() { char englishChar = 'B'; printf("English Character: %c\n", englishChar); return 0; }
Reading English characters from the keyboard in C:
scanf
function with the %c
specifier is used to read English characters from the keyboard.#include <stdio.h> // Reading English characters from the keyboard in C int main() { char userInput; printf("Enter an English character: "); scanf(" %c", &userInput); // Note the space before %c to consume the newline printf("You entered: %c\n", userInput); return 0; }
Handling English characters in string manipulation in C programming:
#include <stdio.h> #include <string.h> // Handling English characters in string manipulation in C programming int main() { char name[20] = "John"; printf("Length of name: %zu\n", strlen(name)); return 0; }
Comparing and sorting English characters in C:
strcmp
and qsort
.#include <stdio.h> #include <string.h> // Comparing and sorting English characters in C int main() { char str1[] = "apple"; char str2[] = "banana"; // Comparing strings if (strcmp(str1, str2) < 0) { printf("%s comes before %s\n", str1, str2); } else { printf("%s comes before %s\n", str2, str1); } return 0; }
Working with English characters in character arrays in C:
#include <stdio.h> // Working with English characters in character arrays in C int main() { char greeting[] = "Hello, World!"; printf("Greeting: %s\n", greeting); return 0; }
File I/O operations with English characters in C language:
#include <stdio.h> // File I/O operations with English characters in C language int main() { FILE *file = fopen("example.txt", "w"); if (file != NULL) { fprintf(file, "This is an English text.\n"); fclose(file); } return 0; }
Unicode and extended character sets in C programming:
#include <stdio.h> // Unicode and extended character sets in C programming int main() { wchar_t unicodeChar = L'�'; // Unicode character printf("Unicode Character: %lc\n", unicodeChar); return 0; }