Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;循环和扫描验证字母、大写字母和数字_C++_C_While Loop_Scanf - Fatal编程技术网

C++ C++;循环和扫描验证字母、大写字母和数字

C++ C++;循环和扫描验证字母、大写字母和数字,c++,c,while-loop,scanf,C++,C,While Loop,Scanf,我的代码有一些问题,它出现在我编译和运行代码后,它将输出两次,而且输出错误 我的任务是反复输入数字/字母/大写字母,并相应地输出结果。至于while循环,我相信我必须把while(1) #包括 int main() { 字符c; int-num; printf(“\n输入字符:”); scanf(“%c”、&c); 如果((c>='a'&&c='a'&&c 首先,如果 其次,要测试数字用法c>='0'&&c,您需要这样做: #include <stdio.h> int main()

我的代码有一些问题,它出现在我编译和运行代码后,它将输出两次,而且输出错误

我的任务是反复输入数字/字母/大写字母,并相应地输出结果。至于while循环,我相信我必须把
while(1)

#包括
int main()
{
字符c;
int-num;
printf(“\n输入字符:”);
scanf(“%c”、&c);

如果((c>='a'&&c='a'&&c

首先,如果


其次,要测试数字用法
c>='0'&&c,您需要这样做:

#include <stdio.h>

int main()
{
 char c;
int num, int general=0;

printf("\nEnter a character: ");
scanf("%c", &c);



if ((c >= 'a' && c <= 'z')) {
    printf("%c\nIt is an alphabet.", c);
    general++;
  }


if ((c >= 'A' && c <= 'Z')){
    printf("%c\n It is a capital alphabet.", c);
    general++;
  }

if (c <= '1' ||c >= '1') {
    printf("\nIt is a numeric");
    general++;
  }


if (general==0)
    printf("error");

 return 0;
}
#包括
int main()
{
字符c;
int num,int general=0;
printf(“\n输入字符:”);
scanf(“%c”、&c);

if((c>='a'&&c='a'&&c)应该有一个
else if
chain…而它不在那里…
if(c='1'))是错误的。-你试过调试代码吗?请确保你确切知道你正在学习什么语言。你的代码类似于C和C++是非常不同的语言。你不应该像WRT这样写比较来确定一个字符的类别。你有<代码> STD::IsSuth,<代码> STD::ode>std::isdigit
用于此目的。例如,如果您的系统是EBCDIC,则小写比较将失败。让标准函数确定字符类别——它知道您可能不知道的所有这些细节。是的。@LogicStuff。在此之前,我想到了使用ASCII值。
#include <stdio.h>

int main()
{
 char c;
int num, int general=0;

printf("\nEnter a character: ");
scanf("%c", &c);



if ((c >= 'a' && c <= 'z')) {
    printf("%c\nIt is an alphabet.", c);
    general++;
  }


if ((c >= 'A' && c <= 'Z')){
    printf("%c\n It is a capital alphabet.", c);
    general++;
  }

if (c <= '1' ||c >= '1') {
    printf("\nIt is a numeric");
    general++;
  }


if (general==0)
    printf("error");

 return 0;
}