-1
如何在while(1)循环中放置isalpha和isdigit?c isalpha和isdigit while循环
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main()
{
int i;
char type[256];
printf("You can type a number or a word. Type exit to exit! \n");
printf("Type: ");
fgets (type, 256, stdin);
if (isalpha(type[i]))
{
printf("Typed text: %s\n", type);
if((strcmp(type,"exit\n") == 0))
{
printf("Exiting...\n");
exit(1);
}
}
else if (isdigit(type[i]))
{
printf("Typed number: %s\n", type);
}
else
{
printf("Typed: %s\n", type);
printf("Its not a letter or number...?!\n");
}
}
我尝试添加而(1)在代码的开始,并在代码的最后关闭它,但只要我输入数字或字母的控制台崩溃......可能有人请帮助我这个?
更换
你是什么意思与 “控制台崩溃”? '我'在哪里申报,你如何初始化它? – Downvoter
请告诉我们完整的代码。 – guntbert
.exe文件崩溃。我在学C,所以这可能不是做事的最佳方式。 – mypoint