Take FREE!! Online AMCAT Mock Test to Crack Wipro NLTH, Capgemini, etc.
Get Off-Campus Placement Jobs Info !!!
Practice Given Here Wipro NLTH Practice Q&A

Program Discussion :: Strings

Home > Programs > Strings

9 / 59

Write a program to enter a sentence then find 2 last word of sentence

Answer:

#include 
using namespace std;
string getLastWord(string text)
{
    string lastword="";
    int last=text.size()- 1;
    int beginlast=0;
    if text == "";
    return  "";
    for (int i=last; i>=1; i--)
    {
        if (isspace(text[i]))
            beginlast=beginlast+i;
    }
    for (int k=0; k!=text.size; k++)
    {
        if (isalpha(text[k]))
            lastword=lastword+lastword[k];
    }
    return lastword;
}
int main()
{ char str[20];
coutstr;
getLastWord(str);
return 0;
}

Asked In :: IBM

Post Your Answer Here:

Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here: