You are here:

C++/C Program to remove blanks??

Advertisement


Question
Hi,

I want to write a program that takes a stream of characters from the keyboard and filters out the blanks.

I am new C programming and am finding it very difficult.

Please help

Answer
This is a C++ forum, so I will answer the question as how I would do it in C++.

#include <string>
#include <iostream>
#incldue <cctype>

std::string get_string_ignore_space() {
  std::string s;
  char c;
  while(cin >> c) {
     if(!std::isspace(c)) s += c;
  }
  return s;
}

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Amit Kumar

Expertise

I can answer Cplusplus language and library questions, including STL, ACE, Boost. I have a good background in Mathematics.

Experience

Programming in CPP for about 8 years. Industry experience of 4 years.

Education/Credentials
Bachelors and Masters in Computer Science from Indian Institute of Technology Delhi.

©2016 About.com. All rights reserved.