一、atoi操作的意思
1.atoi是将字符串转成整型
二、直接使用数组atoi操作
#include<stdio.h>//预编译处理 #include<stdlib.h>//为了使用atoi(字符串转整型),itoa(整型转字符串) 静态内存开放 int main() { int num = atoi("123"); printf("整型:%d", num); }
ps:直接调用需要头文件#include<stdilb.h>
二、通过自己的数组进行atoi操作
#include<stdio.h>//预编译处理 #include<assert.h>//断言 #include<string.h>//为了使用string_len(求长度),,char*arr(指针),strcpy(),stremp() #include<ctype.h>//为了使用判断是否字母,数字,空格 #include<stdlib.h>//为了使用atoi(字符串转整型),itoa(整型转字符串) 静态内存开放 #include<math.h>//为了使用pow int GetBitNum(const char* str) { int count = 0; int len = strlen(str); for (int i = 0; i < len; i++) { if (str[i] >= '0' && str[i] <= '9') { count++; if (!isdigit(str[i + 1])) { break; } } } return count; } int my_atoi(const char* str) { assert(str != NULL); //删除字符串开头的空格 while (*s
对数据atoi操作
最新推荐文章于 2024-10-26 13:41:25 发布