我需要用数字替换我的输入字母。
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