468,490 Members | 2,645 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,490 developers. It's quick & easy.

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 24171
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 discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.