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

  • SEARCH
  • Home
  • 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 4091482
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:22:21+00:00 2026-05-20T19:22:21+00:00

Hi Just started learning c for uni (usually use objective c) and have run

  • 0

Hi
Just started learning c for uni (usually use objective c) and have run into a strange issue with scanf, i have the following code

   while(stringCheck == 0){
    scanf("%c",&computerType);
    computerType = toupper(computerType);

    if ( computerType == 'L') {
        /*set stringCheck to 1 so the scanf while loop breaks*/
        stringCheck = 1; 
        counter = 0;
    } else {
        printf("ERROR\n");
    }
}

This i printing out “ERROR” then asking for input (so it is skipping the scanf statment the first time). If i change the it to another variable that is a string it works fine, it stops on the first time.

The rest of the code works fine, its just the fact that it print an error as soon as it enters the loop that is annoying.

I have tried getChar() and it does the same thing.

Thank you for any help you have to offer.

  • 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-05-20T19:22:21+00:00Added an answer on May 20, 2026 at 7:22 pm

    If it’s printing an error the first time you enter the loop, then there’s already something in the input buffer. I’ll guarantee (assuming your compiler is not brain-dead) that it is not skipping the scanf. You should check what it’s actually receiving by changing:

    printf("ERROR\n");
    

    to:

    printf("ERROR, code = %02x\n", computerType);
    

    I would suggest that it’s the newline from the last time your program ran that code (you say it’s the first time but it’s unclear as to whether you mean the first time into that loop ever (since program started) or first time entering that loop but you’ve been through it before on this program run.

    When you enter LENTER the first time, your code will pull out the L but not the ENTER. If you then call that code again, it will get the ENTER key.

    You should either understand and allow for what’s actually entered or use a safe and sound input function like this one.

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

Sidebar

Related Questions

I just started learning Objective-C and OOP ... so I have very stupid question
just started learning Rails and have managed to import a csv file into a
I just started learning C but I don't understand this part of the code.
I just started learning targets, and have followed all the instructions to create my
Just started learning PySide and is having problem with QTimer I have this #!/usr/bin/python
I just started learning Backbone.js, and have been working on (what else) a simple
I just started learning SL. I have tried to resize all the elements inside
Just started re-learning Haskell (did it at uni but forgot most of it) and
I just started learning C++ couple of weeks ago. So now I have this
I just started learning portlet and got stuck in the first place. I have

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.