Algorithm: (break the line into words)
Remember the position of the character.
You go on each character of the line, until you find a space, a period, a comma or any other character separator - this will be the end of the word.
You take a substring from the first position (p.1) to the received one - this will be the word itself.
Go further until the delimiter characters run out. How to end - this is the beginning of the next word. Next - item 1 and so on until the end of the line.
#include <stdio.h> #include <string.h> #include <iostream> using namespace std; main() { char *tempSlova = new char[20]; char *myString = new char[100]; cout << "Vvedite stroky "; gets(myString); cout << "Slova v stroke:" << endl; for(int i = 0, k =0 ; i <= strlen(myString); i++, k ++) { if(myString[i] == ' '|| myString[i] == '\0') { tempSlova[k] = '\0'; if(tempSlova[0]=='\0') tempSlova[0]=0; printf("%s ", tempSlova); k=-1; } else tempSlova[k] = myString[i]; } return 0; }
int main() { ...- Igor