字符转数字

#include <stdio.h>
#include <stdlib.h>

int transform(char str[]){
    int i = 0;
    int result = 0;
    while(str[i] != '\0'){
        result = result * 10 + str[i] - '0';
        i++;
    }
    return result;
}

main(){
    char* str = "1234";
    int result;
    result = transform(str);
    printf("%d \n", result);
}

 

posted @ 2014-03-06 10:02  yutoulck  阅读(135)  评论(0编辑  收藏  举报