Am trying to make while loop in my C code
like this:
main()
{
char q ;
while( a == 'yes' )
{
/* my code */
printf("enter no to exit or yes to continue");
scanf("%s",q);
}
}
but when i input the char ” q ” …. the console is crashed
and stop working
what is my wrong in while loop ??
There are several errors:
"yes", not'yes'.scanfexpects an address of the variable:scanf("%s", &q), notscanf("%s", q).char q[4]), not character one (char q).areferenced in conditionwhile( a == 'yes')isn’t declared.'\n'is printed.So what you probably need is:
P.S. I thought about constructing a format string to avoid duplication of
3, but my laziness won.