How to convert a string to integer in C?

后端 未结 12 1733
清酒与你
清酒与你 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 01:59

    Don't use functions from ato... group. These are broken and virtually useless. A moderately better solution would be to use sscanf, although it is not perfect either.

    To convert string to integer, functions from strto... group should be used. In your specific case it would be strtol function.

提交回复
热议问题