c - How to convert a character array to a decimal integer array?
问题描述
I would like to convert a character array
to a decimal array
. For example, in the extended ASCII Table, lowercase q is 113. I would ask a prompt to get a text from the user and then the user might input "qqq", then input[] would be ['q','q','q'] and intinput[] would be ['113','113','113'].
Is there a way to do this? Thank you
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';
}
the "intinput[l] = input[l] - '0';"
does not work.
解决方案
In the for loop try
for(l =0; input[l]!= '\0'; l++)
{
intinput[l] = (int)input[l];
}
推荐阅读
- hadoop - Hive:获取数据时出错
- flutter - 加载数据时制作骨架屏幕的最简单方法
- c# - 如何在 razor 视图引擎中获取集合中项目的元数据?
- html - 除非子文本下降到两行,否则 DIV 上方的额外空间?
- python-3.x - Python 从 FTP 服务器下载最新的 CSV
- python - 使用 Django 用户模型
- c# - 构建错误 TFS 2015“没有适当的映射存在...”到映射之外的代码
- python - 测试准确度为 98% 的模型的混淆矩阵不准确
- reactjs - ReactJS 工作流程以及如何捕获按钮点击
- javascript - 检测chrome是否正在加载缓存页面?