display each word of the sentence on a new


//* Write a program where the user is prompted to enter a sentence *
//* or phrase. Then display each word of the sentence on a new *
//* line. *
//* *
//* EXAMPLE: If the user entered *
//* THE RAIN IN SPAIN FALLS MAINLY ON THE PLAIN *
//* the output would be *
//* THE *
//* RAIN *
//* IN *
//* SPAIN *
//* FALLS *
//* MAINLY *
//* ON *
//* THE *
//* PLAIN




#include<iostream>
using namespace std;

int main()
{//top of main
//declare variables local to main
int x,i;
char phrase[50]="\0";
cout<<"Please enter a centence or a phrase!";
cin.get(phrase,49,'\n');



i dont konw how to do next, i need help
Could just replace each space (ASCII 32) in your string with a newline (\n), then output it normally.
You can use either std::istringstream or standard C function strtok. Or you can write yourself the required algprithm.


use strtok function that works perfect

if you still need help follow up this link you might get some ideas how to use strtok.

http://www.cplusplus.com/forum/general/47680/
Topic archived. No new replies allowed.