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 6146817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:00:38+00:00 2026-05-23T19:00:38+00:00

Going through K&R, I’m trying to get my head around C. I want to

  • 0

Going through K&R, I’m trying to get my head around C.
I want to write a program that prints on the screen the user’s previous line, unless the character was “a”.

int main(){

int c;

while((c=getchar())!=EOF){

     if(c!='a')
            putchar(c);
}
return 0;
}

Yes, the program isn’t much. But it won’t work as intended. Do I need to use the ASCII value of the character “a”, because the above code just prints all the letters regardless of being a or not.

  • 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-23T19:00:38+00:00Added an answer on May 23, 2026 at 7:00 pm

    The code should work as specified, but what you will find is that using getchar with the while loop will print a carriage return when a is entered. This is because in the current implementation getchar will keep reading the input buffer till it is empty, if you wanted to stop this happening you could flush it in the if statement.

    Entering a string of text at the moment will print the string removing any *a*s

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

Sidebar

Related Questions

I want to get C code after going through preprocessor AND constant propagation and
I'm going through K&R and 3-2 looks like it would be easy to get
I am going through the Head First PHP & MySQL book right now, and
I was going through k&r complicated declarations part.I got doubt about this particular declaration.
All, I'm going through the Friedman & Felleisen book A Little Java, A Few
Going through happstack-lite tutorial : we build functions that have return type of ServerPart
While going through SWig generated wrappers, I find that the PInvokes don't have any
I'm going through the Beginning iPhone Development book & stuck in chapter 9. I've
I'm going through the features of social auth (http://code.google.com/p/socialauth/) & wondering if this is
After going through a bunch of threads, I know that I need to use

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.