Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-26-2005, 06:39 AM   #1
Registered: Dec 2004
Posts: 44

Rep: Reputation: 15
convert unsigned char * to unsigned long int

I am writing program in which i require to have unsigned char * string say (af03d) to be converted to unsigned long int. Which function is avail to me? i am sending that to other program and want that program to recover the unsigned long int to unsigned char * variable.
Old 04-26-2005, 06:58 AM   #2
Registered: Mar 2005
Location: India
Distribution: Red Hat Linux 8.0
Posts: 5

Rep: Reputation: 0
The function atoi converts strings to integers. it returns the integer on success, else 0. for ex, if str="1234" it returns 1234, if str="123a0f" it will return 0.

the function itoa does the reverse
Old 04-26-2005, 10:13 PM   #3
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
strtol is actually the best of the string to long functions (in the bsd/unix stdc world).

long strtol (char *string, char **endptr, int base);
Pass the string in as the first argument. The 2nd argument is a pointer to the element of the string you want to stop converting at (if you want it to convert until it can't go any further pass in NULL for 2nd parameter). The last parameter is the base of the number. For instance, if the string is "123A" and you pass the base in as 10 you will get 123 as your number (it will stop at A). If your base is 16 it will convert the A as well since it is a valid hex digit.

Also, itoa does not exist in the unix world, snprintf is what you can use as an equivalent.

EDIT: The function is available in stdlib.h....

Last edited by jtshaw; 04-26-2005 at 10:15 PM.
Old 04-27-2005, 12:38 AM   #4
Registered: Mar 2005
Location: India
Distribution: Red Hat Linux 8.0
Posts: 5

Rep: Reputation: 0
thanks jtshaw, that function was unknown to me,...


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
printf unsigned long long int? blackzone Programming 9 03-04-2008 01:41 PM
How to print unsigned long int alaios Programming 6 07-14-2005 11:27 AM
64 bit CPU unsigned long int GodSendDeath Programming 8 03-29-2005 02:19 PM
int value larger then unsigned long jpc82 Programming 3 03-12-2004 04:54 PM
convert from char* to unsigned char* D J Linux - Software 2 02-20-2004 05:09 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:40 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration