home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / me34src.zip / me3 / util / catstrs.c < prev    next >
C/C++ Source or Header  |  1995-01-14  |  2KB  |  82 lines

  1. /* 
  2.  * Author:
  3.  *   Lloyd Zusman        UUCP:   ...!ames!fxgrp!ljz
  4.  *   Master Byte Software    Internet:   ljz%fx.com@ames.arc.nasa.gov
  5.  *   Los Gatos, California    or try:   fxgrp!ljz@ames.arc.nasa.gov
  6.  *   "We take things well in hand."
  7.  * 
  8.  * Public Domain
  9.  * C Durland 3/92 added stdarg support
  10.  */
  11.  
  12. #ifdef __STDC__
  13.  
  14. #include <stdarg.h>
  15. #define VA_START va_start
  16.  
  17. #else    /* __STDC__ */
  18.  
  19. #include <varargs.h>
  20. #define VA_START(a,b) va_start(a)
  21.  
  22. #endif
  23.  
  24. /*
  25.  * catstrs(result, string1, string2, ..., NULL)
  26.  *
  27.  * Concatenate string1, string2, ... together into the result,
  28.  *   which must be big enough to hold all of them plus a trailing
  29.  *   '\0'.  Returns the address of the result.
  30.  *
  31.  *   Example:
  32.  *    char result[100];
  33.  *    (void)catstrs(result, "This", " ", "is a ", "test", (char *)NULL);
  34.  *    result now contains "This is a test".
  35.  */
  36. #ifdef __STDC__
  37. char *catstrs(char *result, ...)
  38. #else
  39. char *catstrs(result, va_alist) char *result; va_dcl
  40. #endif
  41. {
  42.   va_list ap;        /* argument list pointer */
  43.   char *cp, *sp;
  44.  
  45.   VA_START(ap,result);
  46.  
  47.   sp = result;
  48.  
  49.   /*
  50.    * Loop through all the arguments, concatenating each one to the
  51.    *   result string.
  52.    */
  53.   for (cp = va_arg(ap, char *); cp; cp = va_arg(ap, char*))
  54.       while (*cp != '\0') *sp++ = *cp++;
  55.   *sp = '\0';        /* we need a trailing '\0' */
  56.  
  57.   va_end(ap);
  58.  
  59.   return result;
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. /* ****************  TEST ********************* */
  70. #ifdef TEST
  71.  
  72. main()
  73. {
  74.   char result[100];
  75.  
  76.   (void)catstrs(result, "This", " ", "is a ", "test", (char *)0);
  77.  
  78.   puts(result);
  79. }
  80.  
  81. #endif
  82.