Saturday, September 17

Reverse words in a string using Recursion

Write a program to perform the following to any input string:
     
       Input : Structure is a derived datatype
      output: erutcurtS si a devired epytatad

My Code:

#include<stdio.h>
#include<string.h>
int main()
{
    char line[20],word[10];
    int i,j=0,len;
    printf("Entera string :  ");
    gets(line);
    len=strlen(line);
    for(i=0;i<len;i++)
    {
    while(line[i]!=' '&&i<len)
    word[j++]=line[i++];
    for(j--;j>=0;j--)
    printf("%c",word[j]);
    printf(" ");

    j=0;
    }
    getch();
    return 1;
}


I hope this code was useful for u!!
Have a better program for ths prblm??
Feel free to comment it here..!!  :):):)

0 comments :

Post a Comment