-2

Possible Duplicate:
Convert char array to single int?

How to convert char array to uintmax_t? char array contains the uintMax_t value but in string format. Thank you.

Community
  • 1
  • 1
Malay
  • 51
  • 1
  • 4
  • C or C++? [What have you tried?](http://whathaveyoutried.com) – Carl Norum Jan 05 '13 at 05:48
  • How is this different from converting character string to integer, which might have dozens of duplicate already? – Alok Save Jan 05 '13 at 05:49
  • I was thinking that atoi function will convert only string to integer but not the long integer. I thought this function might not work. But I tried in following way and it is working: #include #include #include int main () { time_t rawtime; char s1[64]; uintmax_t u1; rawtime = time(NULL); printf ( "Current local time : %ju \n",(uintmax_t)rawtime ); sprintf(s1,"%ju",(uintmax_t)rawtime); printf ( "Current local time : %s \n",s1 ); u1 = atoi(s1); printf ( "Current local time : %ju \n",u1 ); return 0; } Have I tried right? – Malay Jan 05 '13 at 06:04

1 Answers1

0

You need to use atoi or atol .

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • Yes thanks. I have used it in this way. Is it correct? #include #include #include int main () { time_t rawtime; char s1[64]; uintmax_t u1; rawtime = time(NULL); printf ( "Current local time : %ju \n",(uintmax_t)rawtime ); sprintf(s1,"%ju",(uintmax_t)rawtime); printf ( "Current local time : %s \n",s1 ); u1 = atoi(s1); printf ( "Current local time : %ju \n",u1 ); return 0; } – Malay Jan 05 '13 at 05:58
  • Compile and run it. Does it work? – Jonathon Reinhart Jan 05 '13 at 06:24