[英]Convert a string to unsigned long long int in C
How can I convert a string to an unsigned long long int? 如何将字符串转换为unsigned long long int?
The problem is that if I use strtol
that returns a long int, but I need to convert a string longer than that. 问题是,如果我使用
strtol
返回一个long int,但是我需要转换一个比该字符串更长的字符串。
There is strtoull()
which sounds like a very good match: 有一个
strtoull()
听起来很不错的搭配:
unsigned long long int strtoull(const char *nptr, char **endptr, int base);
No idea why you didn't find it. 不知道为什么你找不到它。
You can use strtoll
for long long
type. 您可以将
strtoll
用于long long
类型。
You can also use sscanf
with %ll
format specifier to convert to long long
. 您还可以将
sscanf
与%ll
格式说明符一起使用,以转换为long long
。
Also, you can write your own implementation if it does not fulfill your purpose. 另外,如果实现不符合您的目的,则可以编写自己的实现。
如果只有一个标准的库函数可以扫描格式化的字符串... sscanf
strtoll
应该做您想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.