Given a string str consisting of a sentence, the task is to reverse every word of the sentence except the first and last character of the words.
Input: str = “geeks for geeks”
Output: gkees for gkees
Input: str = “this is a string”
Output: tihs is a snirtg
Approach: Break the string into words using strtok(), now for every word take two pointers i and j pointing to the second and the second last character of the string respectively. Swap these characters then increment i and decrement j. Repeat these steps while i < j.
Below is the implementation of the above approach:
gkees for gkees
- First substring whose reverse is a word in the string
- Capitalize the first and last character of each word in a string
- Remove the first and last character of each word in a string
- Print last character of each word in a string
- Print the first and last character of each word in a String
- Reverse all the word in a String represented as a Linked List
- Reverse each word in a linked list node
- 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
- 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
- Map every character of one string to another such that all occurrences are mapped to the same character
- String containing first letter of every word in a given string with spaces
- Most frequent word in first String which is not present in second String
- Replace every character of a string by a different character
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.