我需要通過the_message_array循環,然後打印字母表中的字母,當它相當於the_alphabet_array中的數字時。 The_alphabet_array的元素與字母匹配,即the_alphabet_array [0]匹配a,the_alphabet_array [1]匹配b,依此類推。我不能使用ascii,這些字母指向the_alphabet_array中的特定數字。如果還有另一種更簡單的方法來做到這一點,而不是通過26條if語句,我會非常感謝幫助。 這裏是字母陣列:C - 使用指針來創建更多高效的循環遍歷字母表
2, 0, 15, 14, 24, 6, 19, 9, 25, 13, 7, 5, 21, 10, 12, 11, 4, 22, 23, 20, 17, 8, 18, 3, 1, 16
這裏是消息數組:
15 ,12,10,19,22,2,20,17,5 ,2,20,25 ,12 ,10 ,23
所以 'A' 點到2字母表陣列中, 'B' 指向0,等。當2發生在消息數組中,打印出'a'。
int the_letter_char[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','w','x','y','z'};
int message_equals_cipher = 0;
for(message_equals_cipher; message_equals_cipher < 15; message_equals_cipher++){
if(the_message_array[message_equals_cipher] == the_alphabet_array[0]){
printf("%c", the_letter_char[0]);
}
if(the_message_array[message_equals_cipher] == the_alphabet_array[1]){
printf("%c", the_letter_char[1]);
}
if(the_message_array[message_equals_cipher] == the_alphabet_array[2]){
printf("%c", the_letter_char[2]);
}
}
對不起,我沒有具體說明,但我不能使用ASCII值。我編輯了我的問題和代碼以獲取更多細節。 – lchristina26