Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > char array to integer

Reply
Thread Tools

char array to integer

 
 
hedylogus
Guest
Posts: n/a
 
      08-25-2003
I need to convert a char array to its corresponding unsigned integer value.
For example, if

char[0]=x (equivalent to 120)
char[1]=y (=121)
char[2]=z (=122)

then my integer value would be 120121122. My array is 32 char long...is
there a better way to do that than this:

char c_array[32], i_array[96];
i=sprintf ( i_array, "%u%u%u....%u", c_array[0],
c_array[1],...,c_array[31] );
my_int = atoi (i_array);

(i made i_array 96 since each char can be represented by a 3 digit number)

thanks.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
length of 2D Array >> char **myString= (char **) malloc (sizeof (char *)); davidb C++ 0 09-01-2006 03:22 PM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
Problem- strcat with char and char indexed from char array aldonnelley@gmail.com C++ 3 04-20-2006 07:32 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
char->integer, integer->char commands christophergraber@gmail.com Perl Misc 5 11-22-2005 07:13 AM



Advertisments