【发布时间】:2021-03-20 12:13:19
【问题描述】:
当我运行这个程序时,它会打印问题并从用户那里得到答案,但它没有说明它是正确的还是错误的。请帮忙!
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
void
correct (char str[])
{
char c1 = "Cristoforo";
char c2 = "cristoforo";
char c3 = "CRISTOFORO";
int conf = strcmp (str, c1);
int conf1 = strcmp (str, c2);
int conf2 = strcmp (str, c3);
if (conf1 == 0 || conf == 0 || conf2 == 0)
{
printf ("The answer is correct");
}
else
{
printf ("The answer is wrong");
}
}
int
main ()
{
char s[] = "What's the name of the explorere Colombus?\n";
char r[100];
printf ("%s", s);
gets (r);
void correct (r);
}
【问题讨论】:
-
因为你根本没有调用函数
correct。void correct(r);只是声明它,而不是调用它。 -
注意编译器警告 - 代码还有其他问题,例如
char c1 = "Cristoforo";应该是char c1[] = "Cristoforo";