介紹 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);示例
以下是使用 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
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP