472,123 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

right padding


Is it possible to right pad with "0" (or other character != blank) ?
for example :
1 , length 10 ="1000000000"
I've tried with sprintf but I can only left pad with "0" or right pad
with blanks =>
"1 "

Oct 21 '08
52 7377
Richard Heathfield wrote:
Pilcrow said:
s = malloc(width+1);
assert(s != NULL);

Bad idea. Use assertions only when the program is incorrectly written.
Correction: assert() is for detecting "impossible" conditions that can
only happen due to bugs. It is _not_ for handling normal error
conditions, because that error handling will disappear when you've
disabled assertions.

Nov 10 '08 #51
Tim Rentsch said:
Richard Heathfield <rj*@see.sig.invalidwrites:
>Pilcrow said:
s = malloc(width+1);
assert(s != NULL);

Bad idea. Use assertions only when the program is incorrectly written.

Using assertions inappropriately means the program is incorrectly
written, wouldn't you say? ;) ;) ;)
Aye! Lousy wording, wasn't it? I should have written something like:

Use assertions only to test assumptions in your code that must be true if
the program is correctly written. For example, if a particular function is
inside a data "firewall" such that it is *impossible* for it to be called
with invalid data, then it's okay (and in fact a good idea) to write
something like:

assert(temperature MELTING_POINT &&
temperature < BOILING_POINT);

What we're actually testing here is not the data, but the "firewall".

The assertion would be inappropriate, however, in the "firewall" code
itself. For example, if a user has just typed this stuff in, you wouldn't
want to bomb out if he typo'd; you'd just want to prompt him with an error
message and a request to re-enter the data.

Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 10 '08 #52
On 28 Oct, 15:23, Pilcrow <Pilcr...@gmail.comwrote:
In the function, as written, I cannot see how the user can free the
buffer, since it is internal to the function. *I have, however, dealt
with the problem of ever-increasing memory allocation by saying:
s = malloc(width+1);
assert(s != NULL);

I don't think Richard's response to this was adequate, so I'm
going to say it more clearly.


This is absolutely the wrong way to use assert. Using assert
this way means that you believe it is logically impossible
for malloc to return NULL. I hope you don't believe that.
Nov 10 '08 #53

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Marek Mand | last post: by
19 posts views Thread by ashkaan57 | last post: by
11 posts views Thread by john_aspinall | last post: by
6 posts views Thread by maya | last post: by
1 post views Thread by bogdan | last post: by
reply views Thread by leo001 | last post: by

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.