#include<stdio.h> int main() { int c, q = 1; while ((c = getchar()) != EOF) {//用getchar()可以边读取边处理 if (c == ‘"‘) { printf("%s", q ? "“" : "”"); q = !q; } else printf("%c", c); } return 0; }
#include "stdafx.h" #include<stdio.h> char s[] = "`1234567890-=qwertyuiop[]\asdfghjkl;‘zxcvbnm,./";//注意“\\”给\转义 int main() { char c; int i; while ((c = getchar()) != EOF) { for (i = 1; s[i] && s[i] != c; i++); if (s[i]) putchar(s[i - 1]); else putchar(c); } }
测试
#include<stdio.h> char s[] = "abc"; int i[] = { 1,2,3 }; int main() { printf("%d\n", i[3]); printf("%d\n", s[3]); printf("%c\n", s[3]); if (s[2]) printf("%s", "success"); if (s[3])printf("%s", "faile"); }
原文:https://www.cnblogs.com/ZengWeiHao/p/10355541.html