关于atoi和itoa的初步认识
-
atoi实现的功能是将字符串转换为整数
-
搜索帮助文档可得其有关的函数原型
-
参数str为将转换的字符串。函数返回解释生成的int值类型字符为数字。
了解了它的相关功能后,编写的代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <ctype.h>
//将字符串转成数字"123"->123,"1256"->1256
//字符串的开头可以是空格,-
long long Myatoi(const char *str)
{
assert(str != NULL);
if(str == NULL)
return 0;
int flg = 1;//符号
long long tmp= 0;//防止数据溢出
while(