c语言逆序

Posted codeworkerliming

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c语言逆序相关的知识,希望对你有一定的参考价值。

#include <stdio.h>
#define MAXS 20

void reverse( char *p );


void reverse( char *p )

    int i = 0, q = 0, h, tmp;
    while (p[i] != ‘\0‘)
        i++;
    h = i - 1;
    while (q <= h)
    
        tmp = p[q];
        p[q] = p[h];
        p[h] = tmp;
        q++;
        h--;
    
    return ;


int main()

    char str[MAXS]="hello";

    //ReadString(s);
    reverse(str);
    printf("%s\n", str);

    return 0;

  

以上是关于c语言逆序的主要内容,如果未能解决你的问题,请参考以下文章

用C语言写 字符串逆序输出

c语言字符串逆序输出。

用C语言将一个整数逆序输出(用自定义函数)

C语言将字符串逆序输出问题(用函数)

c语言:将递归的方法将一个正整数逆序输出

C语言,编写一个函数:将给定字符串逆序