c语言字符串转换为long_C:将字符串转换为long

c语言字符串转换为long

How to convert a string to long in C?

如何在C中将字符串 转换为long?

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值