Link to home
Start Free TrialLog in
Avatar of csindorf
csindorf

asked on

right filling string till length = 5

Here is my code for starters:
if(strlen(wc)==0)
{
    /*5 spaces */
    strcpy(wc,"     ");
    strcat(com_buffer, wc);
}
else
{  
   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.

TIA

Craig
ASKER CERTIFIED SOLUTION
Avatar of imladris
imladris
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of csindorf
csindorf

ASKER

BINGO