介绍 C 语言中的字符操作
在 C 编程语言中,字符可以是 (A-Z(或)a-z)、数字 (0-9)、一个空格或一个特殊符号。
声明
以下是 C 编程中字符操作的声明 -
char a= ‘A’; using a character constant.
字符输入/输出函数
字符输入/输出函数的解释如下 -
示例 - char a;
scanf("%c", &a); printf ("%c", &a); a = getchar ( ); putchar (a); a = getch ( ); putch (a);
Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.
示例
以下是使用 getchar() 进行行计数的 C 程序 -
#include <stdio.h> /* count lines in input */ main(){ int count, num; printf("enter multiple statements and Press cntrl+z:
"); num = 0; while ((count = getchar()) != EOF) if (count == '
') ++num; printf("%d
", num); }
输出
以下为程序的输出 -
enter multiple statements and Press cntrl+z: Hi Hello Welcome To My World ^Z 4
广告