Converting a Long Long to a Char Buff

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Apr 2008
Posts: 9
Reputation: Swift7625 is an unknown quantity at this point 
Solved Threads: 0
Swift7625 Swift7625 is offline Offline
Newbie Poster

Converting a Long Long to a Char Buff

 
0
  #1
Apr 7th, 2008
Hello All,

I have been trying to convert a long long to a char buff and having problems.

I have tried spintf, and some casting but still can not get the conversion right.

Any help would be great!

Steve
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Converting a Long Long to a Char Buff

 
0
  #2
Apr 7th, 2008
Post an attempt - and mention your OS/Compiler..
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 9
Reputation: Swift7625 is an unknown quantity at this point 
Solved Threads: 0
Swift7625 Swift7625 is offline Offline
Newbie Poster

Re: Converting a Long Long to a Char Buff

 
0
  #3
Apr 7th, 2008
Well I am on Tandem Mainframe.

I have tried a few:

char buff[30];
long long lval;

memset(buf, 0, sizeof buf));
sprintf(buff, "%f", lval);
" %d "
" %u "

memcpy(buff, (char *)lval, sizeof(lval));

My std libs do not appear to have ltoa functions, juts atol, etc.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,813
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Converting a Long Long to a Char Buff

 
0
  #4
Apr 7th, 2008
So your compiler supports long long, but no way to format it into a string? I find that hard to believe, did you check your compiler's documentation? At the very least there should be a non-standard function or extension that supports what you want.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 9
Reputation: Swift7625 is an unknown quantity at this point 
Solved Threads: 0
Swift7625 Swift7625 is offline Offline
Newbie Poster

Re: Converting a Long Long to a Char Buff

 
0
  #5
Apr 7th, 2008
I tried functions as ltoa, itoa, etc and I took a look at my std libs and their is no ltoa conversion listes just the opposite.

I am dealing with a 64 bit value goinf to a array of chars and I do not see anything special for that.

short is support to but thier is no special call functions for it.

What calls do you suggest and I can look in my libs to see if they are there. This compiler is pretty old I think as I have found it missing other calls.

I am on contract here and not an employee.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,813
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Converting a Long Long to a Char Buff

 
0
  #6
Apr 7th, 2008
>I am dealing with a 64 bit value goinf to a array of
>chars and I do not see anything special for that.
Don't just look at the headers, check the documentation. I'm reasonably sure that if the compiler supports long long, it provides a format specifier for sprintf as well.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 9
Reputation: Swift7625 is an unknown quantity at this point 
Solved Threads: 0
Swift7625 Swift7625 is offline Offline
Newbie Poster

Re: Converting a Long Long to a Char Buff

 
0
  #7
Apr 7th, 2008
Originally Posted by Narue View Post
>I am dealing with a 64 bit value goinf to a array of
>chars and I do not see anything special for that.
Don't just look at the headers, check the documentation. I'm reasonably sure that if the compiler supports long long, it provides a format specifier for sprintf as well.
I am looking believe me! This contract sucks they do not use C at all but for this project was needed and they have a weak C environment. I am probably the only to have used the C compiler in ages!

I was just wondering if thier was a manual mathmatical way to do it?

Thanks Steve
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,813
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Converting a Long Long to a Char Buff

 
0
  #8
Apr 7th, 2008
>I was just wondering if thier was a manual mathmatical way to do it?
Well, long long is just another integer type, so converting it to a string is really no different from writing your own itoa function (or lltoa, as it were). If I were you[1], I would start looking for source code to itoa variations online (of which there are many). Chances are good you can change int to long long and be ready to go. You might have to look out for range assumptions, but aside from that the conversion should be trivial.

[1] If I were me, which I am, I would write my own from scratch because I've done it before and have sufficient experience implementing libraries to trust my own skills over some random snippet I found on the web.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 9
Reputation: Swift7625 is an unknown quantity at this point 
Solved Threads: 0
Swift7625 Swift7625 is offline Offline
Newbie Poster

Re: Converting a Long Long to a Char Buff

 
0
  #9
Apr 7th, 2008
Originally Posted by Narue View Post
>I was just wondering if thier was a manual mathmatical way to do it?
Well, long long is just another integer type, so converting it to a string is really no different from writing your own itoa function (or lltoa, as it were). If I were you[1], I would start looking for source code to itoa variations online (of which there are many). Chances are good you can change int to long long and be ready to go. You might have to look out for range assumptions, but aside from that the conversion should be trivial.

[1] If I were me, which I am, I would write my own from scratch because I've done it before and have sufficient experience implementing libraries to trust my own skills over some random snippet I found on the web.

Thanks I will look for that and I may have to do some bit shifting that I was trying to avoid! It just seems it is all catered to go from ascii to int, long, etc.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,958
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 307
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: Converting a Long Long to a Char Buff

 
0
  #10
Apr 8th, 2008
I've had this problem in the past. I used a custom function made by someone else, because I couldn't write my own...

Click
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC