#include <stdio.h>#include<stdlib.h>#include<string.h>intString2int (Const Char*string){ intValue =0; intindex =0; for(;string[Index] >='0'&&string[Index] <='9'; Index + +) {Value= value *Ten+string[Index]-'0'; } returnvalue;}intString_reverse (Char*strsrc) { intLen =0; inti =0; Char* Output =NULL; Char* Pstr =strsrc; while(*pstr) {Pstr++; Len++; } Output= (Char*)malloc(len); if(Output = =NULL) {Perror ("malloc"); return-1; } for(i =0; i < Len; i++) {Output[i]= Strsrc[len-i-1]; printf ("output[%d] =%c\n", Len-i-1, Strsrc[len-i-1]); } Output[len]=' /'; strcpy (strsrc, Output); return 0;}intInt2string (intValueChar*output) { intindex =0; if(Value = =0) {output[0] = value +'0'; return 1; } Else { while(value) {Output[index]= value%Ten+'0'; Index++; Value/=Ten; } string_reverse (output); return 1; }}intMain () {#if0Char string[ A] ="1234"; intValue = String2int (string); printf ("value =%d\n", value);#endif Char string[ -] = {0};intValue =123; Int2string (Value,string); printf ("int_to_string=============:%s\n",string); return 0;}
The result of the code operation is:
C Language implementation int conversion string