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;
}

  

posted @ 2019-10-06 14:43  wdliming  阅读(532)  评论(0编辑  收藏  举报