#include<stdafx.h>#include<stdio.h>#include<stdlib.h>#include<string>#include<iostream>using namespace std;string temp[10];void extract(char * c){    int ind = 0;    //char *temp = (char *)malloc(sizeof(char));    while(*c!= NULL)    {        if(*c!= ' ') // read all chars in a word and store in temp.        {        temp[ind]= temp[ind] + *c;        c++;        }        else if(*c== ' ') // reached end of word        {        c++;        ind++;        }    }    int length = sizeof(temp)/sizeof(temp[0]);    printf(The reversed string is);    for(int i=length;i>=0;i--)    {    cout<<temp[i];// not able to print it with printf statement    }}void main(){char *c = seattle is good;extract(c);}This should print the sentence in reverse order . Input is seattle is goodOutput for the above will be good is seattleI have 2 questions , 1. I am using string array here with size of 10. How can I make it dynamic?2. For some reason the printf(%s,temp[i]) was not giving me correct results(At the very end of extract method). I then used cout and it was fine. Any ideas why? Am I doing something silly?Algorithm Description: Take the input string as char array.Extract words from the string by looking for empty space. Store each word in a temp string array.temp[0] = seattletemp[1] = istemp[2] = goodThen loop backwards through this temp array and print contents.
Reverse a word using string manipulation
c++;array