我怎么能转换成字符整数 [英] how can I convert character to integer number

查看:73
本文介绍了我怎么能转换成字符整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何改变字符(串)到一个整数数组,而无需使用任何现成的功能(例如与atoi();),例如: -

How could I change an array of character (string) to an integer number without using any ready function (ex atoi();) for example :-

 char a[5]='4534';

我要的号码4534,我怎样才能得到它?

I want the number 4534 , How can I get it ?

推荐答案

不使用任何现有的库,你必须:

Without using any existing libraries, you have to:


  1. 转换字符数字。

  2. 联合位数,以形成一个数字。

转换字符位数:

digit = character - '0';

形成许多:

number = 0;
Loop:
number = number * 10 + digit;

您的功能则要检查+和 - 。和其他非数字字符

Your function will have to check for '+' and '-' and other non-digits characters.

这篇关于我怎么能转换成字符整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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