Home
       0019-strncat.c - scc - simple c99 compiler
  HTML git clone git://git.simple-cc.org/scc
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
       0019-strncat.c (830B)
       ---
            1 #include <assert.h>
            2 #include <stdio.h>
            3 #include <string.h>
            4 
            5 /*
            6 output:
            7 testing
            8 test1
            9 test2
           10 test3
           11 test4
           12 test5
           13 done
           14 end:
           15 */
           16 
           17 int
           18 main()
           19 {
           20         char *s, buf[40], buf2[40];
           21 
           22         puts("testing");
           23 
           24         puts("test1");
           25         strcpy(buf, "01234");
           26         s = strncat(buf, "567", 8);
           27         assert(s == buf);
           28         assert(!strcmp(s, "01234567"));
           29 
           30         puts("test2");
           31         strcpy(buf, "01234");
           32         s = strncat(buf, "567", 2);
           33         assert(s == buf);
           34         assert(!strcmp(s, "0123456"));
           35 
           36         puts("test3");
           37         strcpy(buf, "01234");
           38         memcpy(buf2, "567", 3);
           39         s = strncat(buf, buf2, 3);
           40         assert(s == buf);
           41         assert(!strcmp(s, "01234567"));
           42 
           43         puts("test4");
           44         strcpy(buf, "01234");
           45         s = strncat(buf, "", 7);
           46         assert(s == buf);
           47         assert(!strcmp(s, "01234"));
           48 
           49         puts("test5");
           50         strcpy(buf, "01234");
           51         s = strncat(buf, "", 0);
           52         assert(s == buf);
           53         assert(!strcmp(s, "01234"));
           54 
           55         puts("done");
           56 
           57         return 0;
           58 }