D
D
DDD2019-01-30 21:46:58
C++ / C#
DDD, 2019-01-30 21:46:58

How to make a caesar cipher encrypt data after a space?

Here is my code

void Caesar()
{
  char mas[50] = { 0 };
  std::cout << "slovo" << std::endl;
  std::cin >> mas;
    if (std::strlen(mas) != ' ')
    {
      for (int i = 0; i < std::strlen(mas); i++)
      {
        mas[i] += 3%26;
        std::cout << mas[i];
      }
    }
    else
    if (std::strlen(mas) == ' ')
    {
      for (int i = 0; i < std::strlen(mas); i++)
      {
        mas[i] += 3;
        std::cout << mas[i];
      }
    }
}
int main() {
  Caesar();
  _getch();
  return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
@
@pestunov, 2019-02-24
_

Use getline(cin, *) instead of cin. cin treats a space as the end of input, but getline does not.
Run these code snippets and you'll understand

string s2;
  getline(cin, s2);
  cout << s2 << endl;

string s1;
  cin >> s1;
  cout << s1 << endl;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question