String to integer

This tip submitted by Mayur Avhad on 2005-02-08 23:55:27. It has been viewed 25208 times.
Rating of 5.9 with 277 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!