Dumb C coding question.

I was messing around with C last night following a few examples in the book "C in Easy Steps" and I wrote some code for which I get a cast error. I delved into the brief pointers section of the book, but it didn't help clarify how to solve the problem. (Sorry I can't be exact, I left the actual code at home). The code segment went something like this:


char yesno;

do
{
printf("\n Again (y/n)?");
scanf("%c", &yesno);
}
while (yesno="y");

I also tried something like:


char yesno;
char *yesno_ptr=&yesno;

do
{
printf("\n Again (y/n)?");
scanf("%c", &yesno);
}
while (*yesno="y");

I realize it's a pretty dumb question, but I'm hoping the answer will help clarify pointers a bit.

Thanks,

Charles

Comments

I think your first looks the most like what you want. Your problem is the
while(yesnow="y");

It probably should be
while(yesnow=='y');

The double equals == means test for equality. This single equals means assign this value. (As the value is non-zero it will evaluate to true).