String to integer

This tip submitted by Mayur Avhad on 2005-02-08 23:55:27. It has been viewed 29572 times.
Rating of 5.5 with 304 votes

You can use sscanf to convert a string to an integer:


int main()
        char *str="12";
        int i;
        sscanf(str, "%d", &i);
        printf("%d\n", i);
        return 0;

More tips

Help your fellow programmers! Add a tip!