when I run this program it prints the question and it gets the answer from the user, but it does not say if it's correct or false. Please help!
#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);
}
void correct(r)
is declaration and it means - correct is a function that takes r type in arguments and returns void. Just remove void
to call function. correct(r)
. And you need to change char
s to char *
or const char*
.
const char *c1 = "Cristoforo";
const char *c2 = "cristoforo";
const char *c3 = "CRISTOFORO";
You are getting a seg
fault due to incorrect use of strcmp()
. The second parameter is required to be a const char *__s2
. So what would be right is:
int conf = strcmp(str, "Cristoforo");
int conf1 = strcmp(str, "cristoforo");
int conf2 = strcmp(str, "CRISTOFORO");
and also remove void
when calling correct(r)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.