atol() v/s. strtol()

前端 未结 7 1776
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 19:13

What is the difference between atol() & strtol()?

According to their man pages, they seem to have the same effect as well as matching arguments:

         


        
7条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 19:48

    In new code I would always use strtol. It has error handling and the endptr argument allows you to see which part of the string was used.

    The C99 standard states about the ato* functions:

    Except for the behavior on error,they equivalent to

    atoi: (int)strtol(nptr,(char **)NULL, 10)
    atol: strtol(nptr,(char **)NULL, 10)
    atoll: strtoll(nptr, (char **)NULL, 10)

提交回复
热议问题