如何在C中使用if语句来检查用户输入的字符? [英] How to use an if statement in C to check what character the user has entered?
本文介绍了如何在C中使用if语句来检查用户输入的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,你们这里的初学者程序员。需要帮助。
我尝试过:
我试过简单地用双引号输入字符。希望它能执行,但它只给出一个答案。
Hey you guys beginner programmer here.Need help in this.
What I have tried:
I tried simply putting in the character in double quotes.Hoping it'll execute but it gives only one answer.
推荐答案
In C,双引号分隔字符串:Hello
要指定单个字符,请使用单引号:'H','e','l','l','o'
所以检查用户是否输入了是:
In C, double quotes delimits a string: "Hello"
To specify a single character, use single quotes: 'H', 'e', 'l', 'l', 'o'
So to check if the user entered a yes:
if (inputChar == 'Y' || inputChar == 'y')
{
...
Simply说一个字符串是一个char数组,所以使用有点fuid。看看这个字符串教程。
使用字符串是一项常见的任务,因此学习它的时间很充足。
Simply said a string is a char array, so the use is a bit fuid. Take a look at this string tutorial.
Working with strings is a common task so the time to learn it is well invested.
这篇关于如何在C中使用if语句来检查用户输入的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文