Tag: Implement a function int my_atoi (char s[]) to convert a string to the corresponding integer input 1234 output 1234 input +1234 output 1234 input-1234 output -1234 symbol bit flag
#include <stdio.h>int my_atoi (char s[]) /* String conversion function */{ char* p = s; int flag = 1; int ret = 0; if (*p== '-') { flag=-1; } if ((*p== ' + ') | | (*p== '-')) { p++; } while (*p!= ') ) { if ((*p>= ' 0 ') && (*p<= ' 9 ')) { ret = 10*ret + *p -' 0 '; p++; } } return flag*ret;} Int main () { char s[5]; int ret; gets (s); ret = my_atoi (s); printf ("%d", ret);}
650) this.width=650; "title=" capture. PNG2. PNG "src=" http://s3.51cto.com/wyfs02/M02/74/E8/wKioL1YuFcjTt7WRAAC01wFotJ4515.jpg "alt=" Wkiol1yufcjtt7wraac01wfotj4515.jpg "/>650) this.width=650;" title= "capture. PNG3. PNG "src=" http://s3.51cto.com/wyfs02/M02/74/EB/wKiom1YuFcnQ_H5iAACvtggFrQA675.jpg "alt=" wkiom1yufcnq_ H5iaacvtggfrqa675.jpg "/>650) this.width=650;" title= "capture. PNG4. PNG "src=" http://s3.51cto.com/wyfs02/M00/74/E8/wKioL1YuFirAKtkIAAC2TOjouWM379.jpg "alt=" Wkiol1yufiraktkiaac2tojouwm379.jpg "/>
C Language: Implement a function int my_atoi (char s[]), you can convert a string to the corresponding integer, such as +1234 output 1234