#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
//atoi函数
int str_int(const char* str)
{
const char* ptr = str; //ptr保存str字符串开头
int temp=0;
if (*str == '-'||*str=='+')
{
str++;
}
while (*str!='\0')
{
if (*str < '0'&&*str > '9')
break;
temp = temp * 10 + (*str - '0'); //把单字符转换成整数
str++;
}
if (*ptr == '-')
{
temp = -temp;
}
return temp;
}
void main()
{
printf("Please intput a number string: ");
char str[10];
scanf("%s", &str);
int n = str_int(str);
printf("\nOutput:%d ",n);
system("pause");
}