编程笔记
-
将c转换为小写; 仅限ASCII
#include <stdio.h> int lower(int c){ if (c >= 'A' && c <= 'Z') return c + 'a' - 'A'; else return c; } int main() { int c; while ((c = getchar()) !=…
-
使用getchar()和putchar()将输入复制到输出
#include <stdio.h> int main() { int c; while ((c = getchar()) != EOF) { putchar(c); } }
-
验证表达式getchar()!= EOF是0还是1
#include <stdio.h> int main(void) { printf("Please enter a character:/n"); printf("The expression /"getchar() != EOF/" is %d./n", getchar() != EOF); return 0; }
-
编写程序打印EOF的值
#include <stdio.h> int main(void) { printf("The value of EOF is %d./n", EOF); return 0;// }
-
char变量的数字性质
#include <stdio.h> int main( void ) { char c1 = 'a'; char c2 = 90; /* Print variable c1 as a character, then as a number */ printf("/nAs a character, variable c1 is %c", c1); …
-
打印扩展的ASCII字符
#include <stdio.h> int main( void ) { unsigned char mychar; /* Must be unsigned for extended ASCII */ /* Print extended ASCII characters 180 through 203 */ for (mychar = 180; mychar < 204; m…
-
使用getch()函数读取char并处理非ANSI代码
#include <stdio.h> #include <conio.h> int main( void ) { int ch; while ((ch = getch()) != '/n') putchar(ch); return 0; }
-
使用getch()输入字符串并读取非ANSI代码: /r
#include <stdio.h> #include <conio.h> #define MAX 80 int main( void ) { char ch, buffer[MAX+1]; int x = 0; while ((ch = getch()) != '/r' && x < MAX) buffer[x++] = ch; b…
-
使用getchar()函数读取用户输入
#include <stdio.h> int main( void ) { int ch; while ((ch = getchar()) != '/n') putchar(ch); return 0; }
-
使用getchar()输入字符串
#include <stdio.h> #define MAX 80 int main( void ) { char ch, buffer[MAX+1]; int x = 0; while ((ch = getchar()) != '/n' && x < MAX) buffer[x++] = ch; buffer[x] = '/0'…