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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:43:56+00:00 2026-05-15T22:43:56+00:00

The title pretty much says it all, so here’s the code: #include <stdio.h> /*

  • 0

The title pretty much says it all, so here’s the code:

#include <stdio.h>

/* Program counts blanks, tabs, and newlines */
int main(void)
{
  int c;
  int b, t, nl;

  b = 0;
  t = 0;
  nl = 0;

  while ((c = getchar()) != EOF)
    if (c == ' ')
      ++b;
    if (c == '\t')
      ++t;
    if (c == '\n')
      ++nl;
  printf("Input has %d blanks, %d tabs, and %d newlines\n", b, t, nl);
  return 0;
}

I don’t understand why this doesn’t work. It counts the blanks no problem, but then when it comes to the rest their values always get printed as 0.

More than a “here’s how it should be” answer, I’d really like a “it doesn’t work because… you need to do this because…” answer please. I’m trying to grasp the concepts and actually understand the language more than just know what works and what doesn’t.

Thanks! You guys have been already helped tons :).

  • 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-15T22:43:56+00:00Added an answer on May 15, 2026 at 10:43 pm

    It’s because you’re missing braces for your while loop. Without those braces, the only thing inside the while is the first if statement. That’s why it’s only counting blanks, because you go through the whole file doing that one if statement then, after exiting the loop, c is EOF so neither of the other two if statements will be true.

    That was a tricky one, it’s hard to see because the indentation looks like it should work but, unlike Python, the compiler doesn’t use indentation to figure out where things are 🙂

    If you put a opening brace after the while and a closing brace before the printf, it should count everything.

    In other words, this is what your compiler sees:

    while ((c = getchar()) != EOF) {
        if (c == ' ')
            ++b;
    }
    if (c == '\t')
        ++t;
    if (c == '\n')
        ++nl;
    

    whereas you want:

    while ((c = getchar()) != EOF) {
        if (c == ' ')
            ++b;
        if (c == '\t')
            ++t;
        if (c == '\n')
            ++nl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 524k
  • Answers 524k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If MemberObjects is null you will get this exception if… May 16, 2026 at 9:56 pm
  • Editorial Team
    Editorial Team added an answer Here's how I call the dialog and populate it: $('#calendar').fullCalendar({… May 16, 2026 at 9:56 pm
  • Editorial Team
    Editorial Team added an answer It turns out that one of the behaviors I had… May 16, 2026 at 9:56 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

The title pretty much says it all, but here's some background. We have a
well, the title pretty much says it all. here's a little info: i have
The title pretty much says it all. Some caveats are: I need to be
The title pretty much says it all. When I'm doing some reflection through my
The title pretty much says it all. How can I view the original SQL
The title pretty much says it all. There are tons of scripts out there
Title pretty much says it all. I want to use streeview for an area
The title pretty much says it all...is it a bad idea ? I'd like
The title pretty much says it all. The precise error message that seems to
The title pretty much says it. I have some methods that need to run

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.