数字验证 [英] number validation

查看:74
本文介绍了数字验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我正在编写一个程序,要求用户输入两个数字,然后输出哪个数字大于另一个。程序本身很容易,但我还必须验证它是否是输入的数字。有没有一种简单的方法来验证输入的数字是否真的是数字?


我尝试在if语句中使用它而没有运气。


如果(!isdigit(x))/ *如果x不是数字* /


此外,这是我的第一篇帖子所以如果发布错误或者我应该在发布之前尝试别的东西,请接受我的道歉。

Hi all. I''m writing a program that asks a user to enter two numbers and then outputs which number is larger than the other. The program itself was easy enough however, I also have to validate whether or not it was a number that was entered. Is there a simple way to verify that the numbers entered were actually numbers?

I attempted using this in a if statment with no luck.

if ( !isdigit ( x ) ) /* if x is not a digit */

Also, this is my first post so please accept my apologies if this is posted incorrectly or I was supposed to try something else before posting this.

推荐答案

你能发布你正在使用的库(包括)吗?


另外,您可以尝试参考这个
Can you post the libraries (includes) you are using?

Also, you can try referring to this.



您可以发布您正在使用的库(包括)吗?


另外,您可以尝试参考这个




我实际查看了您在提交帖​​子之前发送给我的链接。我似乎无法使用if / else格式的任何一个语句。


if(!isdigit(x))


printf(" that不是数字\ n");


Else


(运行程序的其余部分)

>
以下是我所包含的图书馆。


#include< stdio.h>


#include< ; ctype.h>


#include< string.h>




I actually looked at the link that you sent me prior to submitting my post. I seem unable to use either statements in if/else format.

if ( !isdigit ( x ) )

printf("That is not a number \n");

Else

(run the rest of the program)

Below are the libraries I''ve included.

#include <stdio.h>

#include <ctype.h>

#include <string.h>


我查看了你发送的其他链接,但似乎更多字符验证。以下是我的代码。我想有一种简单的方法来验证输入的数据是否是数字?如果没有,如果您有任何建议,我可以尝试别的。



BTW非常感谢你的帮助。



I checked out the other link you sent, but it seems more for character validation. Below is my code. I thought there would be a simple way to validate whether or not data entered was a number? If not I can try something else if you have any suggestions.


BTW thanks so much for your help.




展开 | 选择 | Wrap | 行号


这篇关于数字验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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