(Tokenizing and Reversing a Sentence) Write a program that inputs a line of text, tokenizes the line with function strtok and outputs the tokens in reverse order.
What will be an ideal response?
```
#include
#include
using namespace std;
void reverseTokens( char * const ); // prototype
int main()
{
const int SIZE = 80;
char text[ SIZE ];
cout << "Enter a line of text:\n";
cin.getline( text, SIZE );
// call to function reverseTokens
reverseTokens( text );
cout << endl;
return 0; // indicate successful termination
} // end main
// function to reverse the individual tokens
void reverseTokens( char * const sentence )
{
char *pointers[ 50 ]; // array to store entire sentence
char *temp; // store each word
int count = 0; // serve as array counter
// call function strtok to take first word out of sentence
temp = strtok( sentence, " " );
// while temp is not empty
while ( temp )
{
// add the word into the array
pointers[ count++ ] = temp;
// get each subsequent word from the sentence
temp = strtok( 0, " " );
} // end loop
cout << "\nThe tokens in reverse order are:\n";
// loop through the array backwards
for ( int i = count - 1; i >= 0; i-- )
cout << pointers[ i ] << ' ';
} // end function reverseTokens
```
Enter a line of text:
twinkle twinkle little star
The tokens in reverse order are:
star little twinkle twinkle
You might also like to view...
One reason an append query can fail is because of duplicate primary keys in the source and destination tables
Indicate whether the statement is true or false
A(n) ____________________ search works well for elements that are in ascending order.
Fill in the blank(s) with the appropriate word(s).
Use the ____________________ menu to turn on and off the display of information in the status bar.
Fill in the blank(s) with the appropriate word(s).
Describe the meaning of win-win in the context of requirements engineering negotiation.
What will be an ideal response?