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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:00:18+00:00 2026-05-15T20:00:18+00:00

Write a program to copy its input to its output, replacing each string of

  • 0

“Write a program to copy its input to
its output, replacing each string of
one or more blanks by a single blank.”

I’m assuming by this he means input something like…

We(blank)(blank)(blank)go(blank)to(blank)(blank)(blank)the(blank)mall!

… and output it like:

We(blank)go(blank)to(blank)the(blank)mall!

This is probably easier than I’m making it out to be, but still, I can’t seem to figure it out. I don’t really want the code… more so pseudo code.

Also, how should I be looking at this? I’m pretty sure whatever program I write is going to need at least one variable, a while loop, a couple if statements, and will use both the getchar() and putchar() functions… but besides that I’m at a loss. I don’t really have a programmers train of thought yet, so if you could give me some advice as to how I should be looking at “problems” in general that’d be awesome.

(And please don’t bring up else, I haven’t got that far in the book so right now that’s out of my scope.)

  • 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-15T20:00:18+00:00Added an answer on May 15, 2026 at 8:00 pm

    Pseudo code

    while c = getchar:
        if c is blank:
            c = getchar until c is not blank
            print blank
        print c
    

    C

    You can substitute use of isblank here if you desire. It is unspecified what characters contrive blank, or what blank value is to be printed in place of others.

    After many points made by Matthew in the comments below, this version, and the one containing isblank are the same.

    int c;
    while ((c = getchar()) != EOF) {
        if (c == ' ') {
            while ((c = getchar()) == ' ');
            putchar(' ');
            if (c == EOF) break;
        }
        putchar(c);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing K&R's Exercise 1-10 Write a program to copy its input to its
I'm trying to write a basic synchronisation program to copy files between two directories.
I need to write a program that prints 0.(03) for input 1 and 33.
I want to write a program which replaces each specific letter by text according
I am trying a reasonably simple program to test binary input/output. I am basically
I'm reading through K&R and the question is to: write a program to copy
I can write an app that would copy all input from cin into a
I'm willing to write program that after 5 sec shows text that was hidden
If I write program in python 2.7 and I want to run another script
Write a program to determine whether a computer is big-endian or little-endian. bool endianness()

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.