Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- using namespace std;
- int countWords(char* text,char separator);
- void calculateLengthOfWords(char* text,char separator, int* wordsLength);
- int main()
- {
- char text[]="Jebac jebac i sie nie dac";
- char separator=' ';
- int numberOfWords=countWords(text,separator);
- int* wordsLength=(int*)(malloc(numberOfWords * sizeof(int)));
- calculateLengthOfWords(text,separator,wordsLength);
- char** words=(char**)malloc(numberOfWords * sizeof(char*));
- for(int i=0; i<numberOfWords-1; ++i)
- {
- }
- cout<<numberOfWords;
- }
- int countWords(char* text, char separator)
- {
- int i=0;
- int counter=1;
- while(text[i]!='\n')
- {
- if(text[i]==separator)
- ++counter;
- ++i;
- }
- return counter;
- }
- void calculateLengthOfWords(char* text, char separator, int* wordsLength)
- {
- int i=0;
- int wordIndex=0;
- int lastWordPosition=0;
- while(text[i]!='\n')
- {
- if(text[i]==separator)
- {
- lastWordPosition=i-lastWordPosition-1;
- wordsLength[wordIndex]=lastWordPosition;
- cout<<lastWordPosition;
- }
- ++i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement