文字列と数値を取得する関数を作成しようとしています。数値が「0」より大きい場合は、文字列と数値でシーザー暗号を作成しますユーザーが入力しました。たとえば、 - > 'stack'であり、番号は '3' - > 'uvdfn'です。数字が '0'の場合は、文字列を逆にします。たとえば、 'stack' - > 'kcats'シーザー暗号とリバーステキストプログラムの問題
私はコードの問題は何か分かりませんが、何か間違いはありません。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void decryptText(char* encText, int n);
#define STR_SIZE 50
int main(void)
{
\t char str[STR_SIZE];
\t int num = 0;
\t printf("Please enter the string : ");
\t fgets(str, STR_SIZE, stdin);
\t printf("Please enter a number : ");
\t scanf("%d", &num);
\t decryptText(str, num);
system("PAUSE");
\t return 0;
}
void decryptText(char* encText, int n)
{
\t int i = 0;
\t int j = 0;
\t char temp = 0;
\t int strLen = strlen(encText);
\t if (n > 0)
\t {
\t \t for (i = 0; i < strLen; i++)
\t \t {
\t \t \t if (*(encText + i) == ' ') { }
\t \t \t else
\t \t \t {
\t \t \t \t if (*(encText + i) >= 'x')
\t \t \t \t {
\t \t \t \t \t *(encText + i) = (*(encText + i)) - 26;
\t \t \t \t }
\t \t \t \t *(encText + i) = (*(encText + i)) + n;
\t \t \t }
\t \t }
\t \t printf("The array after the program deciphered it : \n");
\t \t printf("%s", encText);
\t }
\t else if (n == 0)
\t {
\t \t for (i = 0; i < strLen; i++)
\t \t {
\t \t \t for (j = 0; j >= 0; j--)
\t \t \t {
\t \t \t \t temp = *(encText + i);
\t \t \t \t *(encText + i) = *(encText + j);
\t \t \t \t *(encText + i) = temp;
\t \t \t }
\t \t }
\t \t printf("The array after the program cracked it : \n");
\t \t printf("%s", encText);
\t }
}
"私はコードの問題が何であるかを知らない" - も、我々はどちらも知らない。何が問題なのか正確に説明するのに2,3分かかるのはなぜですか? (つまり、どの入力をテストしたのか、どのような出力が得られなかったのか、コードをデバッグした時の観察結果など) –
'for(j = 0; j> = 0; j - )'は何もしません。 –
こんにちはバラク、申し訳ありません... 問題は、シーザー暗号の場合は何も起こっておらず、結果を印刷しないということです。 リバーステキストの場合、ユーザーが入力したのと同じ文字列が出力されます。 @barakmanos –