Funktion - MyStrCat

Kurzbeschreibung

Fügt 2 Strings zusammen und kopiert das Ergebnis in einen dritten.

Parameter:

Code

void MyStrCat(char *dst, char *src1, char *src2)
{
  uint8_t srccnt = 0;          
  uint8_t dstcnt = 0;
  uint8_t dstlen = sizeof(*dst) - 1;
 
  while (src1[srccnt])          // Add source 1 to destination
  {
    dst[dstcnt] = src1[srccnt];
    srccnt++;
    dstcnt++;
    dstlen--;
    if (dstlen == 0)            // Prevent overflow of destination variable
    {
      break;
    }
  }
  srccnt = 0;
  while (src2[srccnt])          // Add source 2 to destination
  {
    dst[dstcnt] = src2[srccnt];
    srccnt++;
    dstcnt++;
    dstlen--;
    if (dstlen == 0)            // Prevent overflow of destination variable
    {
      break;
    }
  }
  dst[dstcnt] = 0;              // Add 0 (Null-terminated strings)
}


Letzte Änderung: 2015-02-22 13:16:32
Seite erzeugt in 0.034 Sekunden (6.9 kB)