text: String containing first letter of every word in a given string with spaces | C ++ implementation of the above approach ; we are splitting the input based on spaces ( s ) + : this regular expression will handle scenarios where we have words separated by multiple spaces ; charAt ( 0 ) will pick only the first character from the string and append to buffer ; Driver code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; string processWords ( char * input ) { char * p ; vector < string > s ; p = strtok ( input , " ▁ " ) ; while ( p != NULL ) { s . push_back ( p ) ; p = strtok ( NULL , " ▁ " ) ; } string charBuffer ; for ( string values : s ) charBuffer += values [ 0 ] ; return charBuffer ; } int main ( ) { char input [ ] = " geeks ▁ for ▁ geeks " ; cout << processWords ( input ) ; return 0 ; }