I have more code to this program but I dont want to display it
basically I create an array for a character to be in it, mainly y or n for yes or no, then i use an If statement to check it but it doesnt seem to be working, i got this method to work before, but I don't remember what I did, the worst part is it is very basic!
Code:
#include <stdio.h>
int main()
{
char* ans[12];
printf("Do you want to continue? [y/n]: ");
scanf("%c",&ans);
if( ans == "y")
{
printf("Continuing code here...\n");
return 0;
}
else
{
printf("Didn't work did it?\n");
}
return 0;
}
everything I try to input gives me the same answer "Didn't work did it?"
I even chaned ans to just
char ans
or
char ans[12];
but with those I get Warning: Comparing integer to character or something
so I made it a pointer.
when I do this:
Code:
scanf("%c",&ans);
printf("%c\n",ans); //it displays my character fine
// OR
scanf("%c",&ans);
printf("%s\n",ans); // it still works
I even changed scanf to %s instead of %c, still didn't work right
something wrong with my if statement?
can someone please help me with the solution and an explanation of why my program doesn't work would be appreciated highly.