//Encryption of pass-phrase
char passReverse(char usrPass[]){
    char newPass[pSize];
    int value;
    int randNum;
    int rand_NumOut;

    //Random number generation
    srand(time(0));
    randNum = rand();
    rand_NumOut = ((randNum %12)+2);
    //Reversing array for-loop
    for (int i=0; i<pSize && usrPass[i] != '\0'; i++){
        char letter = usrPass[i];
        newPass[i] = letter;
        int maxVal = strlen(usrPass);
        if (maxVal >=0){
            newPass[i] = usrPass[(maxVal-1)-i];
        }
        cout << newPass[i];
        value = i;
    }
    return value;
}


理想情况下,将rand_NumOut放在最后一个循环之后立即放在newPass []中。

我遇到的问题是,当放置在for循环中时,当然,rand_NumOut放置在数组中的每个字符之后,而当循环之外时,我无法将其放置在数组的内容中。

有什么建议吗?

最佳答案

在for循环的末尾,只需添加行

if(usrPass[i+1]=='\0')
{
//code to insert rand_NumOut
//output rand_NumOut
}

10-06 05:05