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.
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- std::string::append vs std::string::push_back() vs Operator += in C++
- Find a string such that every character is lexicographically greater than its immediate next character
- Replace every character of string by character whose ASCII value is K times more than it
- Replace every character of a string by a different character
- Map every character of one string to another such that all occurrences are mapped to the same character
- Modify the string such that every character gets replaced with the next character in the keyboard
- Replace all occurrences of character X with character Y in given string
- Converting one string to other using append and delete last operations
- Append a digit in the end to make the number equal to the length of the remaining string
- Form N-copy string with add, remove and append operations
- Longest Common Prefix using Character by Character Matching
- Count substrings that starts with character X and ends with character Y
- Shortest distance to every other character from given character
- Check whether the given character is in upper case, lower case or non alphabetic character
- Nearest smaller character to a character K from a Sorted Array
- C program to append content of one text file to another
- Find the character in first string that is present at minimum index in second string
- Convert the string into palindrome string by changing only one character.
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
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.