Function to implement strncat() function in C
| 4 | |
| 5 | // Function to implement strncat() function in C |
| 6 | char* strncat(char* destination, const char* source, size_t num) |
| 7 | { |
| 8 | // make ptr point to the end of destination string |
| 9 | char* ptr = destination + strlen(destination); |
| 10 | |
| 11 | // Appends characters of source to the destination string |
| 12 | while (*source != '\0' && num--) |
| 13 | *ptr++ = *source++; |
| 14 | |
| 15 | // null terminate destination string |
| 16 | *ptr = '\0'; |
| 17 | |
| 18 | // destination string is returned by standard strncat() |
| 19 | return destination; |
| 20 | } |
| 21 | |
| 22 | |
| 23 | #ifndef strcmp |