在本节中,我们将了解如何检查给定字符是数字、字母还是 C 中的某些特殊字符。
字母表是从 A – Z 和 a – z,然后数字为 0 – 9。所有其他字符均为特殊字符。因此,如果我们使用这些条件检查条件,我们可以轻松找到它们。
#include <stdio.h> #include <conio.h> main() { char ch; printf("Enter a character: "); scanf("%c", &ch); if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) printf("This is an alphabet"); else if(ch >= '0' && ch <= '9') printf("This is a number"); else printf("This is a special character"); }
Enter a character: F This is an alphabet
Enter a character: r This is an alphabet
Enter a character: 7 This is a number
Enter a character: # This is a special character
以上就是检查输入字符是字母、数字还是特殊字符在C中的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号