我需要用數字替換我的輸入字母。
a = 00
,b = 01
,c = 02
等等......
我覺得char enc出了點問題,當ch == 'j'
或更高時,程序不起作用。使用C++替換帶有數字的字母
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
#include <stdlib.h>
#include <ctype.h>
int main(){
char ch = 'g'; // this should be replaced with some kind of an input function
char alp[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char enc[26] = {'00', '01', '02', '03', '04', '05', '06', '07', '08', '09',
'10', '11', '12', '13', '14', '15', '16', '17', '18', '19',
'20', '21', '22', '23', '24', '25'};
for(int i = 0; i <= 25; i++)
if(ch == alp[i]){
printf("%c", enc[i]);
break;
}
while(getchar()!='\n');
return 0;
}
這不是C#,'00'或'01'不是單個字符。使enc成爲int數組,並在printf中將句柄的左邊加上零。 – brz 2014-08-31 18:56:14
字符類型只能有一個字母 – 2014-08-31 19:02:28
自從我上次看到'conio.h'已經很長時間了。你在哪裏學習你的C/C++? – pqnet 2014-08-31 19:22:17