2013-01-05 190 views
-2

可能重复:
Convert char array to single int?如何将char数组转换为uintmax_t?

如何转换字符数组uintmax_t型? char数组包含uintMax_t值,但是采用字符串格式。 谢谢。

+0

C或C++? [你有什么尝试?](http://whathaveyoutried.com) –

+0

这与把字符串转换为整数有什么不同,它可能有几十个重复? –

+0

我在想atoi函数只能将字符串转换为整数,而不是长整数。我认为这个功能可能不起作用。但我想在下面的方式,它是工作: 的#include 的#include 的#include INT主要(){ time_t的 rawtime; char s1 [64]; uintmax_t u1; rawtime = time(NULL); printf(“当前本地时间:%ju \ n”,(uintmax_t)rawtime); sprintf(s1,“%ju”,(uintmax_t)rawtime); printf(“当前本地时间:%s \ n”,s1); u1 = atoi(s1); printf(“当地时间:%ju \ n”,u1); return 0; }我试过了吗? – Malay

回答

0

您需要使用atoiatol

+0

是的,谢谢。我以这种方式使用它。这是对的吗? 的#include 的#include 的#include INT主() {time_t的 rawtime; char s1 [64]; uintmax_t u1; rawtime = time(NULL); printf(“当前本地时间:%ju \ n”,(uintmax_t)rawtime); sprintf(s1,“%ju”,(uintmax_t)rawtime); printf(“当前本地时间:%s \ n”,s1); u1 = atoi(s1); printf(“当地时间:%ju \ n”,u1); return 0; } – Malay

+0

编译并运行它。它工作吗? –

+0

是的。这是工作。 – Malay