gpt4 book ai didi

c - 如何在 C 中将 String 转换为 int

转载 作者:太空宇宙 更新时间:2023-11-04 06:44:54 27 4
gpt4 key购买 nike

我有以下要转换为 int 的东西。

char *ptr; // this can point to variable length of string

int balance = functionToConverIntoint(ptr)

那么C“functionToConverIntoint”中有这样的函数可以完成这个工作吗?

最佳答案

检查 strtol() 和 strtoul()。

您想避免使用 atoi(),因为它没有很好的方法来区分字符串“0”和无效数字。

关于c - 如何在 C 中将 String 转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1704411/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com