-
little help required
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.
-
Mmm, fun with pointers, and other types
Minimally, this is what you want
Code:
char ans;
printf("Do you want to continue? [y/n]: ");
scanf("%c",&ans);
if( ans == 'y')
Your type was all wrong, and you want single quotes for chars, not double quotes (strings)
#include <std_disclaimers_about_scanf.h>
-
thanks!
I think thats what I did before but I can't remember
Even though I have been enriched in C for 5 years now I still don't get the concept of pointers to regular etc. and it makes even less sense of why because I program in ASM on occasion.
I guess my stubborn mind is to close minded to see it.
Thanks anyway!
-
-
hey thanks, it makes a little more sense now, but the purpose of pointers eludes me, why not just make regular integers or chars?
is there a specific purpose to pointers....
eh, oh well.
I will figure it out next year
(I finally got accepted into the computer science department)
I wrote some term on why counting in Binary with our fingers is better than using the decimal system
1. We can reach 1023 numbers with both hands
2. Your left hand alone has 31 digits
3. If you someone says high five, then you can flip him off.
reason:
101 = 5 in Binary
or
Middle up
index down
thumb up
I got accepted cuz of that!? That is amazing!