right filling string till length = 5

Posted on 2000-03-28
Last Modified: 2010-04-15
Here is my code for starters:
    /*5 spaces */
    strcpy(wc,"     ");
    strcat(com_buffer, wc);
   if(strlen(wc) != 5);
       /* fill to the right with spaces till length = 5 */
       strcat(com_buffer, wc);
   else strcat(com_buffer, wc);

Where the comment is to fill to the right is where I need to insert the code that will take the length of wc if less than 5 anf fill it to the right with spaces.  So if user inputs "a" wc becomes "a    " and so on.


Question by:csindorf
  • 2
LVL 16

Accepted Solution

imladris earned 50 total points
ID: 2664756
A simple rewrite for the whole thing could be:

while(strlen(wc)<5)strcat(wc," ");

LVL 16

Expert Comment

ID: 2664764
I'm assuming that since your first action in your code is to do a strlen on wc, wc does in fact contain a reasonable string, although it might be a null string.
Given that you can skip the first case since you can append stuff to null strings with strcat.

Author Comment

ID: 2664887

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question