文字を取り、シーザー暗号を使用して1つの値をbにシフトするプログラムを作成したい。これを行うには文字列を使用する必要があります。C言語 - シーザー暗号化プログラム
私の問題は私のプログラムは文字列にユーザーの入力を取らないことです。 (私はguy [10]をscanfに入れようとしましたが、プログラムがクラッシュするだけでしたので、間違った人をそこに置いてプログラムがコンパイルされる可能性があります)。それは名前は、このコンテキスト内のポインタとして扱われます、我々はそれへのポインタを取得する必要はありませんので、guy
として
scanf("%s",&guy);
が配列である:
#include <stdio.h>
int main(){
int i=0; //setting the individual slot number for the array-- later used in the while loop
char guy[10];
printf("Enter Plain Text:");
scanf("%s",&guy); //takes user's input-- such as "abc" and puts it into its respective slot in the array guy[10] r-right?
while (guy[10] != '\0'){ //while loop that runs until it reaches the end of the string
if ((guy[i]) >= 'A' && (guy[i]<= 'Z')){ //moves capital letter values up 1
guy[i]=guy[i]++; //makes the current "slot" number go up 1 value. Example: a = 97 + 1 -> b = 98
}
if ((guy[i]) >= 'a' && (guy[i]) <= 'z'){// moves lower case letter values up 1
guy[i]=guy[i]++;
}
i++; //moves the array's interval up to the next "slot"
}
printf("Encrypted text is: %s",guy);
}
をシーザー暗号を合理的にC言語で実装するための多くの方法であり、このサイトの検索ボックスにある '' Caesar''は、100以上のものを生成します。あなたのコードについて。 'guy [10]'ではなく 'guy [i]'があなたのwhile-condition式に含まれているはずです。 '&guy'ではなく' guy'が 'scanf'に渡されるパラメータでなければなりません。 – WhozCraig
これは本当ですが、どれもC言語にも深くは触れていません –