Same Algorithm must be implemented within a function.
String is accepted in main() and passed to the function.
The code is about reversing each word in string.
code:
#include<conio.h>
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
char a[30];
int i,j,k;
cout<<"Enter the string:" ;
gets(a) ;
for(i=0;a[i-1]!='\0';i++)
{
j=i;
while(a[j]!=' ' && a[j]!=NULL)
j++;
k=j;
while(j>=i)
cout<<("%a",a[j--]);
cout<<" ";
i=k;
}
void YourFunctionName(char a[])
{
// copy paste you algorithm here
}
int main()
{
char a[30];
int i,j,k;
cout<<"Enter the string:" ;
gets(a) ;
YourFunctionName(a);
}