Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Write a C function remove_blanks()that replaces two or more consecutive blanks in the input string by a single blank. For example, if the input is:
"Grim         return      to           the             planet                      of                  apes!!"

Then output should be:
"Grim return to the planet of apes!!"

The function should return the number of blank spaces removed. Remember that string is a null-terminated character array! The function prototype is given below:
C++
int remove_blanks(char input_string[],char output_string[]);


What I have tried:

C LANGUAGE PROGRAM I TRIED BUT COULDNT DO IT SO SOLVE THIS ASAP.
Posted
Updated 19-May-21 2:31am
v2
Comments
Patrice T 19-May-21 7:39am    
Show your code ASAP to get help.
Richard MacCutchan 19-May-21 7:58am    
It is not really difficult. Copy the characters one by one from input_string to output_string. When the character is a space, then ignore all except the first one.
Rick York 19-May-21 11:38am    
nope.
Dave Kreskowiak 19-May-21 14:04pm    
I would highly recommend you DO NOT DEMAND other people do your work for you. You won't like the responses you get back.

Write the algorithm in plain language and then gradually convert it to C.
C
while(the end of input_string has not been reached)
{
   if((the current character in input_string is a blank) and
      (the last character in output_string is a blank)
   {
      increment the count of ignored blanks;
      continue to the next character;
   }

   copy the current character in input_string to output_string;
}
 
Share this answer
 
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
We don't do your homework for you, but here are some resources-for-a-beginner-to-learn-c[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900