有限的数据类型范围 [英] limited range of data type

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

问题描述

if(a [n] ==''a''|| a [n] ==''e''|| a [n] ==''i''|| a [n] == ''o''|| a [n] ==''u''|| a [n] ==''w''|| a [n] ==''y''|| a [n] ==

''h''|| a [n] ==''space''|| a [n] =='' - ''){

基本上我要求程序在遇到任何上述字符时做某事,问题似乎与空间有关。我试过''''哪个不起作用,尝试了unicode用于空间,但它说它只支持c ++,所以我怎么能解决错误警告:由于数据类型的范围有限,比较总是假的?帮助赞赏!

解决方案

a [n] ==''space''


应该是
< br $>
a [n] ==''''


我知道你说这不行,但因为你不知道它是怎么回事工作,我知道这是对空格字符的正确测试我只能假设导致它无法工作的任何问题都是代码中的问题,或者是程序输入数据中的问题。然而,
只检查空格字符,也许你输入数据中的制表符是什么?所以你也可以试试


isspace(a [n]);

$ c $ b在ctype.h中定义,检查所有空白字符空间, tab,new line和carridge返回。


或者你也可以查看标签以及


a [n] ==''\\ \\ t''


使用''''时输出不正确。该程序采用两个词For Example。并对它们进行编码(很像soundex算法)。如果我使用For-Example,输出就可以了。但是取走'' - '并留下一个空格会产生错误的输出。


再次因为你没有提供详细信息,预期的输出和实际输出,你失败了给你的代码我不能发表评论。我只能说是


a [n] ==''''


是对空间的正确测试。

if (a[n] == ''a'' || a[n] == ''e'' || a[n] == ''i'' || a[n] == ''o'' || a[n] == ''u'' || a[n] == ''w'' || a[n] == ''y'' || a[n] ==
''h'' || a[n] == ''space'' || a[n] == ''-''){

Basically im asking the program to do something if it comes across any of the above characters, problem seems to be with the space. Ive tried '' '' which doesnt work, tried the unicode for a space but it said its only supported in c++, so how could I solve the error " warning: comparison is always false due to limited range of data type"? Help appreciated!

解决方案

a[n] == ''space''

should be

a[n] == '' ''

I know you say this doesn''t work but since you don''t say how it doesn''t work and I know that this is the correct test for a space character I can only assume that whatever is causing it to not work is either a problem else where in your code or a problem in the input data to the program.

however that only checks for the space character, perhaps what you have is a tab character in the input data? so you could also try

isspace(a[n]);

defined in ctype.h which checks for all whitespace characters space, tab, new line and carridge return.

or you can check for just tabs as well with

a[n] == ''\t''


When using '' '' the output is incorrect. The program takes two words "For Example" and encodes them (much like the soundex algorithm). The output is fine if I use "For-Example" but taking away the ''-'' and leaving a space gives the wrong output.


Again since you are failing to give detail, the expected output and the actual output, and you have failed to give your code I can not comment. All I can say is that

a[n] == '' ''

is the correct test for a space.


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

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