【发布时间】:2014-02-28 22:50:13
【问题描述】:
C 新手仍在学习。 该程序应该在不需要被要求做任何事情的情况下第一次启动。然后它提示用户继续“Y/N”。我一直有错误谁能告诉我为什么它不起作用我不知道如何处理我从中得到的错误。
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <ctype.h>
void theQnA(char charIn);
int main(void)
{
int answerint = 0;
char charIn;
char anwser;
printf("Enter a character to be examined: ");
scanf("%c", &charIn);
theQnA(charIn);
while (answerint == 0)
{
printf("Would you like to run it again? Y/N\n");
scanf("%c", &anwser);
if (anwser == 'y')
{
printf("Enter in another character buddy\n");
scanf("%c", &charIn);
theQnA(charIn);
}
else (anwser != 'y')
{
answerint = (answerint--);
}
}
printf("Goodbye\n");
return 0;
}
void theQnA(char charIn)
{
if (islower(charIn))
printf("You have entered in a lower case letter dude\n");
else if (isdigit(charIn))
printf("You enterd in a num man\n");
else if (isupper(charIn))
printf("Its upper case man\n");
else if (ispunct(charIn))
printf("You entered in a punctuation!\n");
else if (isspace(charIn))
printf("You enterd in a whitespace dude\n");
else
printf("control char/n");
return;
}
【问题讨论】:
-
你得到什么错误?
-
与错误无关的错字:
printf("control char/n");应该是printf("control char\n");。 -
anwser 或 answer...?该代码有更多问题...
-
answerint = (answerint--);:您不应该分配给在同一语句中递减的变量。如果你只想减少answerint,那么answerint--;会做你想做的事。
标签: c variables loops initialization local