c语言字符串转换为long
How to convert a string to long in C?
Use strtol or strtoul C library:
使用strtol或strtoul C 库 :
strtol man page.
strtoul man page.
strtol手册页 。
strtoul手册页 。
If the value of base is 0, the expected form of the subject sequence is that of a decimal constant, octal constant, or hexadecimal constant, any of which may be preceded by a ‘+’ or ‘-‘ sign. A decimal constant begins with a non-zero digit, and consists of a sequence of decimal digits. An octal constant consists of the prefix ‘0’ optionally followed by a sequence of the digits ‘0’ to ‘7’ only. A hexadecimal constant consists of the prefix 0x or 0X followed by a sequence of the decimal digits and letters ‘a’ (or ‘A’ ) to ‘f’ (or ‘F’ ) with values 10 to 15 respectively.如果base的值为0,则主题序列的预期形式为十进制常数,八进制常数或十六进制常数,其中任何一个都可以以“ +”或“-”符号开头。 十进制常数以一个非零数字开头,并由一系列十进制数字组成。 八进制常量由前缀“ 0”组成,可选的是后面跟数字“ 0”至“ 7”的序列。 十六进制常量由前缀0x或0X组成,后跟十进制数字和字母“ a”(或“ A”)至“ f”(或“ F”)的序列,其值分别为10到15。
Answered by anonymous.
匿名回答。
One piece of example code:
一段示例代码:
long size = strtol(result, NULL, 0);
here, result
is a string.
在这里, result
是一个字符串。
翻译自: https://www.systutorials.com/c-converting-string-to-long/
c语言字符串转换为long