// my_itoa.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> //字符转化成整数 int my_atoi(char s[]){ //确定符号 int i=0; for(i=0;isspace(s[i]);i++)//跳过空白 ; int sign=(s[i]=='-'?-1:1); if(s[i]=='+'||s[i]=='-')//跳过符号 i++; //确定数值 int n=0; for(;isdigit(s[i]);i++){ n=n*10+(s[i]-'0'); } return sign*n; } //整数转化成字符串 void my_itoa(int n,char s[]){ int sign=0; if((sign=n)<0)n=-n; int i=0; do { s[i++]=n%10+'0';//取下一个数字 } while ((n/=10)>0); if (sign<0) { s[i++]='-'; } s[i]='/0'; int j=0; for(j=i;j>=0;j--){ printf("%c",s[j]); } printf("/n"); } int main(int argc, char* argv[]) { char s[]=" -23231345"; int res=my_atoi(s); printf("%d/n",res); int num=-125654; char *a=(char*)calloc(sizeof(char),1000); my_itoa(num,a); return 0; }