Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

lib_str.h/lib_str.c

Prototype

Code Block
LanguageC++
CaptionTextCAPTION
languagecpp
          CPU_CHAR  *Str_Cat_N (       CPU_CHAR    *pstr_dest,
                                const  CPU_CHAR    *pstr_cat,
                                       CPU_SIZE_T   len_max);


Arguments

pstr_dest

Pointer to the string memory buffer to append string characters into.

...

String concatenation terminates if either string pointer points to or overlaps the NULL address.

Example Usage

CAPTION
Code Block
LanguageC++
CaptionText
languagecpp
          CPU_CHAR     AppBuf[30];
          CPU_CHAR    *pstr;
          CPU_SIZE_T   len;
         


          pstr = Str_Copy_N(&AppBuf[0], "Hello World!",  sizeof(AppBuf));
          if (pstr != (CPU_CHAR *)0) {
              len = Str_Len_N(<code >&AppBuf[0], sizeof(AppBuf));
              if ((len + sizeof((CPU_CHAR)'\0'))      /* If 'Hello' string including its NULL character ... */
                       < sizeof(AppBuf)) {            /* ... fits entirely in AppBuf[],                 ... */
                  pstr = Str_Cat_N(&AppBuf[0],
                                   "Goodbye World!",  /* ... concatenate 'Goodbye' string               ... */
                                                      /* ... while limiting to remaining AppBuf[] size.     */
                                   (sizeof(AppBuf) - (len + sizeof((CPU_CHAR)'\0'))));
              } else {
                  printf("COPY STRING IS TOO LONG!");
              }
          }
           
          if (pstr == (CPU_CHAR *)0) {
              printf("STRING COPY/CONCATENATION FAILED!");
          }