Solved

right filling string till length = 5

Posted on 2000-03-28
3
223 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:csindorf
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
imladris earned 50 total points
Comment Utility
A simple rewrite for the whole thing could be:

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

0
 
LVL 16

Expert Comment

by:imladris
Comment Utility
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.
0
 

Author Comment

by:csindorf
Comment Utility
BINGO
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now