473,387 Members | 1,535 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,387 software developers and data experts.

right padding

Hello,

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 =>
"0000000001"
"1 "

Thanks.
Oct 21 '08
52 7738
Richard Heathfield wrote:
Pilcrow said:
>free(s);
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.

S
Nov 10 '08 #51
Tim Rentsch said:
Richard Heathfield <rj*@see.sig.invalidwrites:
>Pilcrow said:
free(s);
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:
--------------------------------------------------------------------
free(s);
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.

DO NOT DO THAT.

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Marek Mand | last post by:
How to create a functional *flexible* UL-menu list <div> <ul> <li><a href=""></li> <li><a href=""></li> <li><a href=""></li> </ul> </div> (working in IE, Mozilla1.6, Opera7 (or maybe even...
3
by: stan | last post by:
I have code that produces 5 boxes across the screen width. So far I have only tested it in IE 6 and NS 8. It works in IE, but in NS I am not able to fit in the 5th box. I am using two...
1
by: Edward | last post by:
Why is it that in this two-column example that (only) in explorer, the text in the right-column moves a couple pixels over to the right whereever there is text across from it in the left hand...
19
by: ashkaan57 | last post by:
Hi, I have a page in a right-to-left language and I am trying to make some bulleted lists using <ul>, but it puts the bullets to the left. Is there any way I can set the bullets to be on the...
11
by: john_aspinall | last post by:
I want to put a simple padding on the right hand side of my text container to stop the text from overflowing out of the box. Ive added a padding-right rule and it refusing to recognise it in...
5
by: Timeri | last post by:
This is a bit confusing until you actually see what I'm talking about but the main content of my page is not growing with the right column. I want the main content (left/larger column) to take into...
6
by: maya | last post by:
hi, I recently discovered the hard way that when you had padding-right or padding-left to a div it increases the with of the div... how do you add left-padding or right-padding to a div w/o...
1
by: bogdan | last post by:
Hi, I have a div to provide a background image for a menu. I'd like to position the menu on the right side but I can't seem to find a right way of doing it. The only way the menu will move to...
3
by: Noorain | last post by:
I designed a site. i want to header,footer,left & right column fixed but body information only scrolling. this site screen to be 800/600 px. i designed this way but when i used position fixed all...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.