How to convert string to integer in UNIX

前端 未结 5 1248
广开言路
广开言路 2020-12-25 11:03

I have d1=\"11\" and d2=\"07\". I want to convert d1 and d2 to integers and perform d1-d2. How do I do this

5条回答
  •  借酒劲吻你
    2020-12-25 11:18

    Use this:

    #include 
    #include 
    
    int main()
    {
        const char *d1 = "11";
        int d1int = atoi(d1);
        printf("d1 = %d\n", d1);
        return 0;
    }
    

    etc.

提交回复
热议问题