cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

strncat.c (380B)


      1#include <string.h>
      2
      3/*
      4 * Concatenate s2 on the end of s1. s1 must be large enough.
      5 * At most n characters are moved.
      6 * Return s1.
      7 */
      8
      9char *strncat(char *s1, const char *s2, int n) {
     10    char *os1 = s1;
     11    while (*s1++) ;
     12    --s1;
     13    while (*s1++ = *s2++) {
     14        if (n == 0) {
     15            *--s1 = '\0';
     16            break;
     17        }
     18        n--;
     19    }
     20    return os1;
     21}