Program in C++, string no longer accepts characters, and hangs the console, what happens?

Asked

Viewed 55 times

0

I made a program in C++ converting morse code to letters.

However this program will receive up to 1000 characters. But I do not know what happens, it receives 400 characters at most, and so the locking console.

What happens?

Follows code below:

#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

string convertMorse(string s) {
cout<<s<<endl;
if(s=="=.===")return "a";
if(s=="===.=.=.=")return "b";
if(s=="===.=.===.=")return "c";
if(s=="===.=.=")return "d";
if(s=="=")return "e";
if(s=="=.=.===.=")return "f";
if(s=="===.===.=")return "g";
if(s=="=.=.=.=")return "h";
if(s=="=.=")return "i";
if(s=="=.===.===.===")return "j";
if(s=="===.=.===")return "k";
if(s=="=.===.=.=")return "l";
if(s=="===.===")return "m";
if(s=="===.=")return "n";
if(s=="===.===.===")return "o";
if(s=="=.===.===.=")return "p";
if(s=="===.===.=.===")return "q";
if(s=="=.===.=")return "r";
if(s=="=.=.=")return "s";
if(s=="===")return "t";
if(s=="=.=.===")return "u";
if(s=="=.=.=.===")return "v";
if(s=="=.===.===")return "w";
if(s=="===.=.=.===")return "x";
if(s=="===.=.===.===")return "y";
if(s=="===.===.=.=")return "z";

return "lixo";
}

int main(void) {

ios_base::sync_with_stdio(false);
cin.tie(0);

int t; cin>>t;
string str;
string saida;

 while(t--) {

    cin>>str;
    string nova;
    int contap = 0;
    for(int i=0;i<str.size();++i) {

        if(str[i]=='=') {

            if(contap==3) {
//              cout<<"n: "<<nova<<endl;
                saida += convertMorse(nova);
                contap=0; nova.clear();
            }

            if(contap==7) {
                    saida+=convertMorse(nova);
                saida+=' ';
                nova.clear();
                contap=0; 
            }

            while(contap>0) {
                contap--; nova+='.';
            }

            nova+=str[i];
        } else {
            contap++;

        }

    }

    saida+=convertMorse(nova);

    cout<<saida<<endl;
    saida.clear();

}


return 0;
}
  • Error on console? Receive 1000 characters from a text file, for example?

1 answer

0


Good guys, Dev C++ was in error, because it was too long open and sometimes generates some bug, this was the reason not reading 1000 characters, I closed the program, put the code and saved again and it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.