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.
- std::string::append vs std::string::push_back() vs Operator += in C++
- Replace every character of string by character whose ASCII value is K times more than it
- Find a string such that every character is lexicographically greater than its immediate next character
- Modify the string such that every character gets replaced with the next character in the keyboard
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Replace all occurrences of character X with character Y in given string
- Map every character of one string to another such that all occurrences are mapped to the same character
- Converting one string to other using append and delete last operations
- Form N-copy string with add, remove and append operations
- Replace every character of a string by a different character
- Append a digit in the end to make the number equal to the length of the remaining string
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Find the character in first string that is present at minimum index in second string
- Queries to find the last non-repeating character in the sub-string of a given string
- Convert the string into palindrome string by changing only one character.
- Queries to find the first non-repeating character in the sub-string of a string
- Replace a character c1 with c2 and c2 with c1 in a string S
- Kth most frequent Character in a given String
- Change string to a new character set
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.