C - Converting from char / string to int using atoi

13. March 2012 08:00

 

This function should probably be avoid since it does not have any error handling and the strtol should be used instead. However it is a quick and dirrty way of converting strings to int's

 

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


int main(int argc, char **argv) {
        char *str = "12345";
        int val = atoi(str);

        printf("%s -> %d\n", str, val);

        return 0;
}

E-mail Kick it! DZone it! del.icio.us Permalink