编程笔记
-
将char类型指定给变量并输出为整数
#include<stdio.h> int main (void) { char c, d; c = 'd'; d = c; printf ("d = %c/n", d); return 0; }
-
输出单个字符
#include <stdio.h> #include <string.h> int main() { int i; char msg[] = "yiibai.com"; for (i = 0; i < strlen(msg); i++) { putchar(msg[i]); //Outputs a single character } putc…
-
读取一个字符
#include <stdio.h> #include <string.h> int main(){ int i; char msg[25]; printf("Type up to 25 characters and then press Enter.../n"); for (i = 0; i < 25; i++) { msg[i] = getc…
-
使用最流行的转义序列
#include <stdio.h> int main() { printf("Column A/tColumn B/tColumn C"); printf("/nMy Computer/'s Beep Sounds Like This: /a!/n"); printf("/"Letz/bs this is a te…
-
printf()转义序列和转换字符
#include <stdio.h> int main() { printf("Quantity/tCost/tTotal/n"); printf("%d/t/t$%.2f/t$%.2f/n", 3, 9.99, 29.97); printf("/b/b/b/b can be fixed with the "); print…
-
使用isdigit()函数检查用户输入
isdigit()函数接受一个参数。 isdigit(x) 如果参数x是一个数字,则isdigit()函数将返回一个true值; 否则,为0或false值。 #include <stdio.h> #include <ctype.h> int main() { char cResponse = '…
-
读取一个字母并检查其值
#include <stdio.h> int main() { char cResponse = '/0'; printf("Enter the letter A: "); scanf("%c", &cResponse); if ( cResponse == 'A' ) printf("/nCo…
-
getch()函数等待按键
getch()不会将字符回显到屏幕上。getche()函数与getch()相同,但键是回显的。 #include <stdio.h> #include <conio.h> #include <ctype.h> int main(void) { char ch; printf("Enter some t…
-
使用getchar()和putchar()从键盘输入字符并以相反的方式显示它们
#include <stdio.h> #include <ctype.h> int main(void) { char ch; printf("Enter some text (type a period to quit)./n"); do { ch = getchar(); if (islower(ch)) ch = toupper(ch); els…
-
从选项列表中选择
#include <stdio.h> int main() { char c; printf("Please make your treat selection:/n"); printf("1 - Beverage./n"); printf("2 - Candy./n"); printf("3 - Hot dog.…