// c2m.cpp - Read from standard input character data and write // to standard output the corresponding Morse code. // In the Morse output codes are separated by spaces // and the ending of words is indicated by six spaces. // The non-morse characters are treated as spaces. // For convenience we print out at most ROWMAX(=60)+6 // characters per row. #include "morse.h" #include #include using namespace std; const int ROWMAX = 60; int main() { bool inword = false; // We are within a word char c; const char *p; int count = 0; while (cin.get(c)) { if (isalnum(c)) { inword = true; } else if (!Morse::ismorse(c)) { if (inword) { cout << " "; // these are 5 spaces count += 5; } inword = false; } cout.put(' '); p = Morse::char2morse(c); cout << p; count += strlen(p); if (count > ROWMAX) { cout << endl; count = 0; } } if (count != 0) cout << endl; return 0; }