Given a string str and a character ch, this article tells about how to append this character ch to this string str at the end.
Input: str = "Geek", ch = 's' Output: "Geeks" Input: str = "skee", ch = 'G' Output: "skeeG"
- Get the string str and character ch
- Use the strncat() function to append the character ch at the end of str. strncat() is a predefined function used for string handling. string.h is the header file required for string functions.
char *strncat(char *dest, const char *src, size_t n)
Parameters: This method accepts the following parameters:
- dest: the string where we want to append.
- src: the string from which ‘n’ characters are going to append.
- n: represents the maximum number of character to be appended. size_t is an unsigned integral type.
- Print or return the appended string str.
Below is the implementation of the above approach:
Original String: Geek Character to be appended: s Appended String: Geeks
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer DSA Live Classes