How to convert a string to integer in C?

后端 未结 12 1569
清酒与你
清酒与你 2020-11-22 01:40

I am trying to find out if there is an alternative way of converting string to integer in C.

I regularly pattern the following in my code.

char s[] =         


        
12条回答
  •  死守一世寂寞
    2020-11-22 02:11

    Yes, you can store the integer directly:

    int num = 45;
    

    If you must parse a string, atoi or strol is going to win the "shortest amount of code" contest.

提交回复
热议问题