String to integer

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



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

#include

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!