C: How to append/concatenate 'x' spaces to a string -


I want to add a variable number of spaces for a string in C, and want to know whether a standard method

  • Please assume that before I called any one of the tasks given below,

This is a way I Used:

  add_spaces (char * dest, int Num_of_spaces) {int i; (Strcat (dest, "");}}  

This is better in a display, but not even standard (i = 0; i

So, do you have any standard solutions for me , So I do not modify the wheel again?

I

 < Code> add_spaces (char * dest, int num_of_spaces) {int len ​​= strlen (dest); mmeset (dest + lane, '', news_f_s És); Dest [len + num_of_spaces] = '\ 0';}  

But as stated in the form of itself, one such task which is the maximum size (in that example < Code> '\ 0' is also included):

  add_spaces (char * dest, int size, int num_of_spaces) {int len ​​= strlen (dest) For the // check I am still guessing to join a valid '\ 0' terminated string, if the LAN is smaller than the size (len + num_of_spaces & gt; = Size) {num_of_spaces = size - len-1; } Memset (Dest + Lane, '', News_of_space); Dest [len + num_of_spaces] = '\ 0'; }  

Comments