2016-09-20 1 views
-2

이것은 Keyshanc 암호화 알고리즘에서 가져온 것입니다. https://github.com/Networc/keyshanc문자 대체를위한 end while 루프

제 질문은 암호 배열에서 선택한 키로 여러 암호화 출력을 갖는이 주 방법을 어떻게 조작 할 수 있습니까?

끝 부분의 인코딩 루프를 벗어날 수 없습니다.

int main() 
{ 
    string password[] = {"JaneAusten", "MarkTwain", "CharlesDickens", "ArthurConanDoyle"}; 

    for(int i=0;i<4;++i) 
    { 
     char keys[95]; 

     keyshanc(keys, password[i]); 

     char inputChar, trueChar=NULL; 
     cout << "Enter characters to test the encoding; enter # to quit:\n"; 
     cin>>inputChar; 

     for (int x=0; x < 95; ++x) 
     { 
      if (keys[x] == inputChar) 
      { 
       trueChar = char(x+32); 
       break; 
      } 
     } 

     while (inputChar != '#') 
     { 
      cout<<trueChar; 
      cin>>inputChar; 
      for (int x=0; x < 95; ++x) 
      { 
       if (keys[x] == inputChar) 
       { 
        trueChar = char(x+32); 
        break; 
       } 
      } 

     } 
    } 
    return 0; 
} 

답변

0

두 곳에서 입력을하고 있으므로 두 가지 테스트를 거쳐야합니다.

루프가 while 인 경우에는 while 루프에서 벗어나 루프 for(;;)에서 벗어나야합니다. for(;;) 루프를 강제로 실행하려면 i=5;을 설정할 수 있습니다. (이 같은 일이에 비록) 또한 trueChar에서

for (int i = 0; i<4; ++i) 
{ 
    char inputChar, trueChar = 0; 
    cout << "Enter characters to test the encoding; enter # to quit:\n"; 

    cin >> inputChar; 

    if (inputChar == '#') //<== ADD THIS 
     break; 

    while (inputChar != '#') 
    { 
     cout << trueChar; 
     cin >> inputChar; 

     if (inputChar == '#') //<== ADD THIS to break out of for(;;) loop 
     { 
      i = 5; 
     } 

    } 
} 

inputChar0하지 NULL으로 초기화되어야한다. 초기화되지 않은 경우 trueChar을 인쇄하지 마십시오.

if (trueChar) 
    cout << trueChar;