Funktion - MyStrRight

Kurzbeschreibung

Diese Funktion kopiert von einem gegebenen String eine gegebene Anzahl Zeichen vom Ende aus in einen anderen String.

Parameter:

Code

void MyStrRight(char *dst, char *src, uint8_t chars)
{
  int8_t srccnt = 0;
  uint8_t dstlen = sizeof(*dst) - 1;
  uint8_t srcchars = 0;
  uint8_t dstptr = 0;
  // Count chars in String
  while (src[srcchars]) 
  {
    srcchars++;
  }
  // Get start position
  srccnt = srcchars - chars;
  // If more chars requested than available: copy all
  if (srccnt < 0)
  {
    srccnt = 0;
  }  
  while (src[srccnt])
  {
    dst[dstptr] = src[srccnt];
    srccnt++;
    dstptr++;
    dstlen--;
    // Prevent overflow of destination variable
    if ((dstlen == 0))  
    {
      break;
    }
  }
  // Add 0 (Null-terminated strings)
  dst[dstptr] = 0;
}
 


Letzte Änderung: 2015-02-22 13:16:31
Seite erzeugt in 0.084 Sekunden (6.8 kB)