c中带有temp变量的字符串的反转 [英] reverse of string in c with temp variable

查看:84
本文介绍了c中带有temp变量的字符串的反转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好吧,

i的代码是c,低于此。这个代码与string相反。我的问题是在while循环时l = pc si siht和p = pc si siht control从rev函数返回

void rev(char * l,char * p)

{

}

那么如何扭转一些词我的意思是编程。我无法理解。





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.


#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

推荐答案

不,你的观察是错误的。



明白这一点,你需要调试你的程序,看看发生了什么。



你发送两个指针l和p。 l是非小数和p。 l增加p减少。他们同时这样做。



因此只要l小于p,while循环就会继续。如果l等于p(当字符串的长度是偶数时)或l大于p(当字符串的长度为奇数时),则循环结束。



最后,进行调试!!
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!!


这篇关于c中带有temp变量的字符串的反转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆