Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7992701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:38:32+00:00 2026-06-04T13:38:32+00:00

Am trying to make while loop in my C code like this: main() {

  • 0

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 ??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:38:35+00:00Added an answer on June 4, 2026 at 1:38 pm

    There are several errors:

    1. String literals should be surrounded by double quotes: "yes", not 'yes'.
    2. String literals can’t be compared to character variables.
    3. scanf expects an address of the variable: scanf("%s", &q), not scanf("%s", q).
    4. Apparently, you need array variable (char q[4]), not character one (char q).
    5. Variable a referenced in condition while( a == 'yes') isn’t declared.
    6. You won’t get your message on the screen since it’s being buffered until '\n' is printed.

    So what you probably need is:

    #include <stdio.h>
    #include <string.h>
    
    #define INP_SIZE 3
    int main() {
        char inp[INP_SIZE + 1] = { 0 };
        while (strcmp(inp, "yes")) {
            printf("enter yes to continue or whatever else to exit\n");
            scanf("%3s", inp);
        }
        return 0;
    }
    

    P.S. I thought about constructing a format string to avoid duplication of 3, but my laziness won.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After trying to make a while(bool) loop and it failing because I couldn't see
Im trying to make a basic while loop example im preperation for my next
Trying to make a simple program to catalogue books. Something like this, for example:
I am trying to make an imageview that rotates while sliding across the screen.
Im trying to make a curtain effect where when the function is executed while
Hopefully I can explain this to where it make sense, but I'm trying to
I'm trying to make an Android game, and I am following a few code
What i am trying to is to do something like this: Print \ then
In this loop, I'm trying to take user input and continually put it in
I'm trying to parse a never-ending xml stream that looks like this: <outer> <foo>footext</foo>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.