我想将一个字符数组
转换成一个十进制数组
。例如,在扩展的 ASCII 表中,小写 q 是 113。我会要求提示从用户那里获取文本,然后用户可能会输入“qqq”,然后 input[] 将是 ['q','q' ,'q'] 和 intinput[] 将是 ['113','113','113']。
有没有办法做到这一点?谢谢
char input[50], ch;
int intinput[50];
int j = 0, l = 0;
printf("Enter Cleartext: ");
while((ch = getchar()) != '\n') {
input[j] = ch;
j++;
}
for(l = 0;input[l] != '\0'; l++) {
intinput[l] = input[l] - '0';
}
"intinput[l] = input[l] - '0';"
不起作用。
最佳答案
在for循环中尝试
for(l =0; input[l]!= '\0'; l++)
{
intinput[l] = (int)input[l];
}
关于c - 如何将字符数组转换为十进制整数数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57839064/