Hi,
    Scroll Down.
----- Original Message -----
Sent: Wednesday, December 29, 2004 8:57 PM
Subject: (PT) HELP(reverse line)

Hi all,

Please help me to get the solution of following program,

Write a function reverse (str) that reverses the character string str.  Use it to write a program that reverses its input a line at a time.

can any one please tell me how can i use function reverse(str) to reverse the line at a time.Just tell me the logic,please.

i am desperately waiting for the solution.

                                                                           Aniruddha


Here's a way of reversing your sentence.
 
void reverse(char *t);
#include<stdio.h>
int main()
{
    char *s; // Eg input sentence: "My name is XYZ"
    printf("Enter a sentence:\n");
    gets(s); 
    reverse(s);
    printf("%s",s); //print the reversed string :O/p is: "ZYX si eman yM"
    return 0;
}
void reverse(char *t)
{
    int i,j;
    char temp;
    for(i=0,j=strlen(t)-1;i<j;i++,j--)
    temp=t[i],t[i]=t[j],t[j]=temp;
}
 
However if you wanted the output as "XYZ is name My", You need to individually reverse the words of the reversed sentence.
Use the logic and thats an assignment for you.
 
HTH
-Ravi


To unsubscribe : [EMAIL PROTECTED]




Yahoo! Groups Sponsor
ADVERTISEMENT
click here


Yahoo! Groups Links

Reply via email to