pengwn 21 Newbie Poster

this part is because after the "up" there is no space
check for "\0"
we store a new word "up" in b[2][0]... or second row of
b[10x20] array.
here wrd=2 and i=0,1,2.. that is 0=u, 1=p, 2='\0'

i=0;
   if(a[x] == '\0')
       for(p=m;p <= x;p++) 
            b[wrd][i++] = a[p];
        b[wrd][i] = '\0';

here b[j] is just that i = wrd and j is the stings
jack
went
up
where b[2][0] = u
b[1][0] = w
b[0][0] = j


for(i=wrd; i >= 0 ; i--) {
        int j = 0;
        while( b[i][j] != '\0')
            cout << b[i][j++];
        cout << endl;
    }

hope you get the idea. just throw in some cout statments in the
code and print b[j] you will get it.

~s.o.s~ commented: Nice +21
pengwn 21 Newbie Poster

the below will reverse your sentence it works.

#include<iostream>
using namespace std;

int main(){
    char a[100];
    char b[10][20];
    int x,m = 0,p,wrd = 0, i = 0;
    
    cout<<"Enter a sentence"<<endl;
    gets(a);
    
    for(x=0; a[x] != '\0'; x++) {
        if(a[x] == ' ') {
            for(p=m;p <= x;p++) 
                b[wrd][i++] = a[p];
            b[wrd][i] = '\0';
            m = x + 1;
            wrd++;
            i = 0;
        }
    }
    i=0;
   if(a[x] == '\0')
       for(p=m;p <= x;p++) 
            b[wrd][i++] = a[p];
        b[wrd][i] = '\0';
        
    for(i=wrd; i >= 0 ; i--) {
        int j = 0;
        while( b[i][j] != '\0')
            cout << b[i][j++];
        cout << endl;
    }
}
pengwn 21 Newbie Poster

I am unable to get the "is" I keep getting the below:

the find : this
the find : this

what I want is:

the find : this
the find : is

from the below code:

typedef multimap<int,string> IntStringMMap;

IntStringMMap coll; // container for int/string values

coll.insert(make_pair(2,"a"));
coll.insert(make_pair(1,"this"));
coll.insert(make_pair(4,"of"));
coll.insert(make_pair(1,"is"));
coll.insert(make_pair(3,"multimap"));


IntStringMMap::iterator post = coll.find(1);
cout << "the find : " << post->second << endl;
post = coll.find(1);
cout << "the find : " << post->second << endl;
pengwn 21 Newbie Poster

The code below gives :
Data is : hello srikanth its me
Data is :
Data is :
Data is :

#include <string>
#include <iostream>
#include <boost/regex.hpp>

boost::regex e("(\\w)\\s*(\\w)\\s*(\\w)");
boost::match_results<std::string::const_iterator> what;


int main()
{
   int i;
   const std::string input = "hello srikanth its me";
   boost::regex_match(input, what, e, boost::match_default | boost::match_partial);

   for ( i = 0; i < 4; ++i )
      std::cout << " Data is : " <<  what[i].str() << std::endl;
}

how do i make it to print:
Data is : hello
Data is : srikanth
Data is : its
Data is : me

pengwn 21 Newbie Poster

Can someone help me out code using the below to get the equivalent program as beneath:

boost::match_results<std::string::const_iterator> what;
boost::regex_match(input, what, e, boost::match_default | boost::match_partial))

#include <iostream>
#include <string>
#include <boost/regex.hpp>

int main()
{
 std::string s = "who, lives:in-a, pineapple under the sea?";

 boost::regex re(",|:|-|\\s+");
 boost::sregex_token_iterator p(s.begin(), s.end(), re, -1);
 boost::sregex_token_iterator end;

 while( p != end)
 std::cout << *p++ << std::endl;
}

Basically I am trying to use a result_match iterator
rather than the std::string::const_iterator rather than boost::sregex_token_iterator

thanks much.