CS50 pset2 Vigenere Cypherのコードは次のとおりです。私はCのプログラミングに新しいです。私のコードで何が間違っていますか? (Vigenere cypher cs50、pset2)
[私はいくつかの提案と(下)このコードを得た後、一度コードを編集した私の新しい編集したコードである。]
私は、コードを実行すると、それは無限ループを生成し、また、新しい暗号化されたテキストは次のように生産されていませんあるはずです。私のコードの修正に関するいくつかの提案やアドバイスをお願いできますか? ありがとう、
#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, string argv[])
{
if (argc != 2) //if it is not rqual to 2, it gives an error message.
{
printf("Enter the valid input : \n");
return 1;
}
if (argc == 2) //if two commands are given then it proceeds to other step.
{
string k = argv[1];
string m = GetString();
int l = strlen(k);
int p = strlen(m);
for(int i = 0; i <= p ; i++) //it has to keep on rotating from 0 to len of string and back to zero and so on.
{
{
i = i % l;
}
if (isalpha(m[i]) && isalpha(k[i])) // it proceeds ahead only if the input given is an alphabet, if the input is sth other than alphabet it prints exactly as it is.
{
for(int t = 0; t <= p ; t++)
{
if(isupper(m[t])) // when is it capital letter.
{
printf("%c", (m[t] - 65 + k[i]) % 26 + 65);
}
if(islower(m[t])) // when it is small letter.
{
printf("%c" , (m[t] - 97 + k[i])% 26 + 97);
}
}
}
else //if it is not an alphabet it returns as it is.
{
printf("%c", m[i]);
}
}
}
printf("\n");
return 0;
}
コンパイラが言ったように、 'p'はポインタ、配列、またはベクトルではありません。それは 'int'です。 –