字母检索出了 什么问题 ?为什么不能准确检测 ??

weixin_36747231 2016-12-14 10:31:48





#include "stdafx.h"
#include<ctype.h>

int _tmain(int argc, _TCHAR* argv[])
{
char ch,ch1;
while(1)
{
printf("input the character('q' to qiut):");
ch=getchar();
ch1=getchar();
if(ch=='q'||ch=='Q')
break;
if(isalpha(ch))
printf("\n%c is a letter.\n\n",ch);
else
printf("\n%c is a not letter.\n\n",ch);
}




return 0;
}
数字 1 也被检测为字母,求指导 。
...全文
135 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_36747231 2016-12-18
  • 打赏
  • 举报
回复
#include "stdafx.h" #include<ctype.h> int _tmain(int argc, _TCHAR* argv[]) { char ch,ch1; while(1) { printf("input the character('q' to qiut):"); ch=getchar(); ch1=getchar(); if( ch=='q'||ch=='Q' ) break; if( isalpha(ch)) printf("\n%c is a letter.\n\n",ch); else printf("\n%c is a letter.\n\n",ch); } return 0; }
ooolinux 2016-12-18
  • 打赏
  • 举报
回复
else printf("\n%c is not a letter.\n\n",ch);
weixin_36747231 2016-12-18
  • 打赏
  • 举报
回复




int _tmain(int argc, _TCHAR* argv[])
{
char ch,ch1;
while(1)
{
printf("input the character('q' to qiut):");
ch=getchar();
ch1=getchar();
if( ch=='q'||ch=='Q' )
break;
if( ch>='a'&&ch<='z' || ch>='A'&&ch<='Z' )
printf("\n%c is a letter.\n\n",ch);
else
printf("\n%c is a letter.\n\n",ch);
}




return 0;
}
++++++++++++++++++++++++
ooolinux 2016-12-18
  • 打赏
  • 举报
回复
if(isalpha(ch)) 改成: if( ch>='a'&&ch<='z' || ch>='A'&&ch<='Z' ) 试试
ooolinux 2016-12-17
  • 打赏
  • 举报
回复
贴代码看看?
weixin_36747231 2016-12-17
  • 打赏
  • 举报
回复


程序运行到哪一步,直接卡死,没有运行出不是字母这个结果 ,仍然错误。
ooolinux 2016-12-15
  • 打赏
  • 举报
回复
if( ch>='q'||ch<='Q' ) 谁说这样改的? if(isalpha(ch)) 改成: if( ch>='a'&&ch<='z' || ch>='A'&&ch<='Z' ) 试试
weixin_36747231 2016-12-15
  • 打赏
  • 举报
回复


不行,还和原来一样 ,问题可#include "stdafx.h"
#include<ctype.h>

int _tmain(int argc, _TCHAR* argv[])
{
char ch,ch1;
while(1)
{
printf("input the character('q' to qiut):");
ch=getchar();
ch1=getchar();
if( ch>='q'||ch<='Q' )
break;
if(isalpha(ch))
printf("\n%c is a letter.\n\n",ch);
else
printf("\n%c is a letter.\n\n",ch);
}
能不在哪。我更改你的代码,可以运行一部分,但是数字仍然无法判断、if( ch>='q'||ch<='Q' )
你的代码接近正确答案了,数字 无法识别,差点。
ooolinux 2016-12-14
  • 打赏
  • 举报
回复
退出:quit
ooolinux 2016-12-14
  • 打赏
  • 举报
回复
if( ch>='a'&&ch<='z' || ch>='A'&&ch<='Z' ) 试试

1,178

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 数据库及相关技术
社区管理员
  • 数据库及相关技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧