#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
#include<ctype.h>//模拟实现atoi
int My_Atoi(const char * str){assert(str);//断言str不是空指针
int flag =1;//为字符串的正负做标志
int ret =0;//返回的数if(*str =='\0')//判断字符串是否为空{return0;}while(isspace(*str))//判断不为空的字符串前面是否有空格{
str++;if(*str =='\0')//判断字符串是否只有空格{return0;}}if(*str =='+')//判断字符串正负{
str++;}if(*str =='-')//判断字符串正负{
str++;
flag =-1;//字符串为负,flag为-1}while(isdigit(*str))//判断是否为数字{
ret = ret *10+(*str -'0')*flag;
str++;}return ret;//返回结果}
int main(){
char str[]="-123a45";printf("%d\n",My_Atoi(str));return0;}
#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h>#include<assert.h>#include<ctype.h>//模拟实现atoiint My_Atoi(const char * str){ assert(str);//断言str不是空指针 int flag = 1;//为字符串的正负做标志 int ret = 0;//返回的数 if (*str == '\0')//判断字符串是否为空 {