C强制转换文字char' 0'设为int 0(零),怎么办? [英] C cast literal char '0' to int 0 (zero), how?

查看:65
本文介绍了C强制转换文字char' 0'设为int 0(零),怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何将文字 char'0'转换/转换为 int 0 ?

How would I go to cast/convert literal char '0' to int 0?

即:

char string[] = "0101";
char ch = string[0];
x = magic(ch);
if (x)
    printf("int zero")

推荐答案

ch = 0;

现在,如果要将 any 数字字符转换为等效的数字字符,则需要类似以下内容:

Now, if you want to convert any digit-character to its numeric equivalent, you'd need something like:

ch = ch - '0';

这篇关于C强制转换文字char' 0'设为int 0(零),怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆