Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi all,
i have a code of c which is below.This code is reverse to string.my question is that in while loop when l=p c si siht and p=p c si siht control return from the rev function
void rev(char *l,char *p)
{
}
then how to reverse the some word i mean rogramming. i am unable to undestand.


C#
#include "stdafx.h"
#include "string.h"
#include "malloc.h"
void rev(char *,char *);
int _tmain(int argc, _TCHAR* argv[])
{
    char a[]="this is c programming";
    char *end;

    for(end=a; *end; end++)
       ;

    rev(a, end-1);
    printf("%s",a);
    return 0;
}

void rev(char *l, char *p)
{
    char t;
    while(l < p)
    {
        t=*l;
        *l++ =*p;
        *p-- =t;
    }

}


Please help me.

Thanks
Posted
Updated 1-Aug-13 11:29am
v2

1 solution

no, your observation is wrong.

First to understand this you need to debug your program and see what happened.

And you are sending two pointer l and p. l is a non fractional number as well as p. l increases p decreases. They do it at the same time.

So the while loop continues as long as l is less than p. If l become equal to p(when the length of the string is even. ) or l is bigger than p(when the length of string is odd) the loop ends.

Finally, do the debug!!
 
Share this answer
 
Comments
[no name] 1-Aug-13 21:31pm    
Forget my previous comment. I think you are saying there is nothing wrong with the code (functionally). I agree.
Mohibur Rashid 1-Aug-13 23:56pm    
He has a question. The way he wrote is very hard to understand. but he has a question, the question is:
when the function returns? he pointed out whether :
at: l="p c si siht"
and
at p="p c si siht"

i.e. he is asking the state of variable l and p right before the function return.

His question is so vague even after understanding I can't re-generate the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900