60 658
Assignments Done
97,7%
Successfully Done
In April 2018

Answer to Question #25582 in C++ for Sam

Question #25582
Please write code on C++ for following problem.
In the given string replace each sequence containing more than one space by one space.
For example: the string “a bcd ef . gh 90” - “a bcd ef . gh 90”
Expert's answer
#include <stdio.h>
#include <string>

int main()
{
char s[256];
gets(s); // read input string
std::string input = s, output;

for (int i = 0; i < input.length(); i++)
& if ( input[i] != ' ' || input[i+1] != ' ' ) // if current or next char
output += input[i]; & & // is not space copy to output

printf("%s\n",output.c_str()); // write output string
getchar();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions