For some reason I can't figure out how to compare the input of a string to the value in an array.
What I'm trying to do is compare the input from the user to the correct answer in the array to see how many they got right.
I'll provide an example of the problem to which I'm trying to solve:
David enters his answers TTTTT
--- the program compares Davids input to the array: TFTFT
--- the program calculates how many David got right in this case 3.
--- the program displays output to the user.
Here is my code (I left out the obvious printf and scanf and a few variable declarations to not crowd up the page):
char correctAnswer[] = "TFTFTFFTFTFT"
char input[15][2]={""}
int f;
int l;
f = strcmp(input[0],correctAnswer);
if (f <= 0)
{
f += 14;
}
printf("you got this amount right: %d\n", f);


Sign In
Create Account

Back to top









