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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:39:42+00:00 2026-05-20T09:39:42+00:00

This is a piece of code I’ve written for a homework. It seems to

  • 0

This is a piece of code I’ve written for a homework. It seems to work but I wonder if I missed something.

The task was to implement a function (here: Countwords) which counts all words in a char *. No library functions should be used.

namespace {

bool IsPrintable(char c) {
  return c >= '!' && c <= '~';
}

void SkipPrintable(const char *&s) {
  do {
    s++;
  } while (IsPrintable(*s));
}

bool IsWhiteSpace(char c) {
  return c == ' ' || c == '\t' || c == '\n';
}

void SkipWhitespace(const char *&s) {
  while (IsWhiteSpace(*s)) {
      s++;
  }
}

} // namespace

int CountWords(const char *s) {
  int count = 0;

  while (*s != '\0') {
    SkipWhitespace(s);

    if (IsPrintable(*s)) {
        count++;
        SkipPrintable(s);
    }
  }

  return count;
}
  • 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-20T09:39:43+00:00Added an answer on May 20, 2026 at 9:39 am

    You solve this in linear complexity. One cannot do the same in less complexity. So you cannot significantly improve your algorithm.

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

Sidebar

Related Questions

This piece of code used to work as expected, but now it seems i
This piece of code used to work in MVC 1 but it does not
this piece of code worked fine on my machine, but it doesn't on my
Is this piece of code where I lock a part of the function correct?
This piece of code causes Chrome to crash: function forecastTemp(forecast) { var end =
This piece of code is working fine with normal php: <?php function barber($type) {
Why this piece of code does not work? How to set the length of
I have this piece of code var f = function() { this.x = 100;
This piece of code is part of a large source code but the bug
This piece of code has previously worked but I have C&P it to a

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.