473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Converting unsigned long to string in C

Hi,
Could any one tell me how to convert a unsigned long value into string
(char *) ?
In C++ there is a function _ultoa so wanted a similar one in C .
Regards,
Shivaraj
Feb 24 '08
107 25833
John Bode wrote:
On Feb 26, 1:26 pm, Richard <de...@gmail.comwrote:
I'm deadly serious about this use of sizeof.

In my 18 years of programming at 6 different companies, I've never
heard anyone rant about sizeof in this manner.
Richard is troll, which is why I killfiled him long ago. He'll "rant"
about anything that he thinks will cause trouble on the newsgroup. It's
best to ignore him if at all possible.


Brian
Feb 27 '08 #101
On Feb 27, 1:43 pm, "Default User" <defaultuse...@yahoo.comwrote:
John Bode wrote:
On Feb 26, 1:26 pm, Richard <de...@gmail.comwrote:
I'm deadly serious about this use of sizeof.
In my 18 years of programming at 6 different companies, I've never
heard anyone rant about sizeof in this manner.

Richard is troll, which is why I killfiled him long ago. He'll "rant"
about anything that he thinks will cause trouble on the newsgroup. It's
best to ignore him if at all possible.

Brian
I don't see him as a troll like Twink and McCormack; he strikes me as
someone who could contribute meaningfully to the group if he just got
over himself.
Feb 27 '08 #102
On Feb 27, 1:47 pm, Richard <de...@gmail.comwrote:
William Pursell <bill.purs...@gmail.comwrites:
>
Would you like to see

printf "hello%s" "world";

or something equally as contrived for example?

I would much rather see:

printf "hello %s\n" "world";

Which, BTW, is actually valid in at least one major language:
$ printf "hello %s\n" "world"
hello world
Feb 27 '08 #103
Ben Bacarisse wrote:
Richard <de***@gmail.comwrites:
.... snip ...
>
>My experience is that almost nowhere other than here have I seen
"sizeof x + y" used in preference to "sizeof(x)+y";

I don't have much code here to scan, but my Linux kernel source
has more than 1200 instances of this form of sizeof. Much less
than the other form, but my point in not about the frequency of
use, but about your insistence than anyone who thinks differently
about is being silly (that is from another post in this thread).
I simply use "y + sizeof x" to avoid reading problems. Similarly I
use "N * sizeof *p".

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Feb 27 '08 #104
In article <47***************@news.sbtc.net>, cr*@tiac.net (Richard Harter) wrote:
>On Wed, 27 Feb 2008 15:25:06 GMT, sp******@milmac.com (Doug
Miller) wrote:
>>In article <fq**********@registered.motzarella.org>, Richard <de***@gmail.com>
wrote:
>>
>>>For starters theres the

"is it sizeof(x)+y" or "sizeof(x+y)" double take.

Don't be ridiculous; the meaning is just as obvious as in
x = y * a + b;

Or do you look at that statement and have trouble deciphering whether the
right side means ((y * a) + b) or (y * (a + b)) ?
I dunno, I would expect that for most people it is not "just as
obvious". That * binds more closely than + is customary usage in
basic algebra. C (and most other computer languages) uses the
same precedence rules as ordinary usage. "sizeof" is an operator
peculiar to C; its precedence is necessarily idiosyncratic.
I disagree with respect to the degree of "obviousness" -- even if sizeof and +
were at the *same* level of precedence, left-to-right evaluation would still
guarantee that "sizeof x + y" would mean "(sizeof x) + y". It takes (IMHO) a
deliberately obtuse interpretation to suppose that it could mean "sizeof (x +
y)" instead.

--
Regards,
Doug Miller (alphageek at milmac dot com)

It's time to throw all their damned tea in the harbor again.
Feb 28 '08 #105
Richard <de***@gmail.comwrites:
Would you like to see

printf "hello%s" "world";

or something equally as contrived for example?
I suggest that your learn about some other programming languages. For
example Haskell or one of the ML familly.

Yours,

--
Jean-Marc
Feb 28 '08 #106
sp******@milmac.com (Doug Miller) writes:
In article <47***************@news.sbtc.net>, cr*@tiac.net (Richard Harter) wrote:
On Wed, 27 Feb 2008 15:25:06 GMT, sp******@milmac.com (Doug
Miller) wrote:
>In article <fq**********@registered.motzarella.org>, Richard <de***@gmail.com>
wrote:
>
For starters theres the

"is it sizeof(x)+y" or "sizeof(x+y)" double take.

Don't be ridiculous; the meaning is just as obvious as in
x = y * a + b;

Or do you look at that statement and have trouble deciphering whether the
right side means ((y * a) + b) or (y * (a + b)) ?
I dunno, I would expect that for most people it is not "just as
obvious". That * binds more closely than + is customary usage in
basic algebra. C (and most other computer languages) uses the
same precedence rules as ordinary usage. "sizeof" is an operator
peculiar to C; its precedence is necessarily idiosyncratic.

I disagree with respect to the degree of "obviousness" -- even if sizeof and +
were at the *same* level of precedence, left-to-right evaluation would still
guarantee that "sizeof x + y" would mean "(sizeof x) + y". It takes (IMHO) a
deliberately obtuse interpretation to suppose that it could mean "sizeof (x +
y)" instead.
If the grammar was changed in the obvious way so that sizeof x + y meant
sizeof(x+y), sizeof(x) + y would also be interpreted as sizeof((x)+y). BTW
sizeof(x)->field currently mean sizeof((x)->field).

Yours,

--
Jean-Marc
Feb 28 '08 #107
In article <fp**********@registered.motzarella.org>,
Richard <de***@gmail.comwrote:
>"J. J. Farrell" <jj*@bcs.org.ukwrites:
>Richard wrote:
>>Richard Heathfield <rj*@see.sig.invalidwrites:

...
char s[(CHAR_BIT * sizeof n + 2) / 3 + 1];

I hate this "fad" of using "sizeof n". It reads horribly.

What ""fad""? sizeof and its usage has been part of C for a long time.

The fad that I have almost never seen it in production code because
.... it reads horribly. Simple. Practical reasons. The clique here use
it all the time because they are the clique.
Richard - face it. For the in-crowd, using parens with sizeof is like
mixing primaries during daylight hours. Not done.

(We'll see if anyone catches the reference. Free peppermint candy to
anyone who does)

Mar 1 '08 #108

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ramesh | last post by:
Hi, I need to convert unsigned long data to a std::string, I googled a bit to see if the string class supports any methods to achieve this - but didnt find any, I think of using sprintf and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.