检查用户是否在 C 中输入字母或数字 [英] Check if User Inputs a Letter or Number in C

查看:26
本文介绍了检查用户是否在 C 中输入字母或数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以调用 C 脚本来查看用户是否输入了英文字母表中的字母?我在想这样的事情:

Is there an easy way to call a C script to see if the user inputs a letter from the English alphabet? I'm thinking something like this:

if (variable == a - z) {printf("You entered a letter! You must enter a number!");} else (//do something}

我想检查以确保用户没有输入字母,而是输入了数字.想知道是否有一种简单的方法可以在不手动输入字母表中的每个字母的情况下提取每个字母:)

I want to check to make sure the user does not enter a letter, but enters a number instead. Wondering if there is an easy way to pull every letter without manually typing in each letter of the alphabet :)

推荐答案

#include <ctype.h>
if (isalpha(variable)) { ... }

这篇关于检查用户是否在 C 中输入字母或数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆