Skip to content

Instantly share code, notes, and snippets.

@jeandudey
Created July 27, 2015 15:49
Show Gist options
  • Save jeandudey/93733cc66d3f9ba5b3b3 to your computer and use it in GitHub Desktop.
Save jeandudey/93733cc66d3f9ba5b3b3 to your computer and use it in GitHub Desktop.
Universal Acronym Generating System [/r/programmingprompts]
#include <iostream>
#include <sstream>
#include <string>
#include <locale>
#define MAX_WORDS 20
std::string acronymise(std::string str)
{
std::string words[MAX_WORDS];
std::string result;
std::locale loc;
std::stringstream tmp(str);
int i = 0;
while (tmp.good() && i < MAX_WORDS) {
tmp >> words[i];
++i;
}
i = 0;
for(i = 0; i < MAX_WORDS; i++)
result += toupper(words[i][0], loc);
return result;
}
int main(int argc, char **argv)
{
std::string input;
std::string EXIT("exit");
std::cout<<"Please enter a string so we can make an Acronym: "<<std::endl<<"> ";
std::getline(std::cin, input);
while(input != EXIT) {
std::cout<<"Result: "<< acronymise(input)<<std::endl;
std::cout<<"Please enter a new phrase to make an acronym or type exit to quit."<<std::endl<<"> ";
std::getline(std::cin, input);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment