1.自己写一个函数(c/c++)
- #include <stdio.h>
- #include <assert.h>
- /* my string to integer function */
- int myfun(char *str){
- int i = 0,n = 0,flag = 1;
- if(str[0] == '-')
- i = 1;flag = -1;
- for(; str[i] != '/0' ; i++){
- assert(str[i] >= '0' && str[i] <= '9');
- n = str[i] - '0' + n*10;
- }
- return n*flag;
- }
- int main(int argc, char *argv[])
- {
- int a;
- char str[] = "1024";
- a = myfun(str);
- printf("%d/n",a);
- return 0;