diff --git a/archive/c/c-plus-plus/remove-all-whitespace.cpp b/archive/c/c-plus-plus/remove-all-whitespace.cpp new file mode 100644 index 000000000..64fc32ce7 --- /dev/null +++ b/archive/c/c-plus-plus/remove-all-whitespace.cpp @@ -0,0 +1,34 @@ +#include +#include +#include // for std::isspace + + +int main(int argc, char* argv[]) { + + // Check if given string passed + if (argc < 2) { + std::cout << "Usage: please provide a string" << std::endl; + return 1; // Return error code if no string is given + } + + // Get the string passed + std::string input = argv[1]; + std::string result; + + // Check if input string is empty + if (input.empty()) { + std::cout << "Usage: please provide a string" << std::endl; + return 1; // Exit error code if the string is empty + } + + for(char c : input) { + // If the character is not a whitespace character, add it to result + if (!std::isspace(static_cast(c))) { + result += c; + } + } + //print out the result (string should have no spaces) + std::cout << result << std::endl; + + return 0; +}