当前位置:网站首页>Function: string storage in reverse order

Function: string storage in reverse order

2022-07-06 14:35:00 |Light|

requirement

Write a function , Make an input string stored in reverse order .

Code

#include<string.h>
#include<stdio.h>
/* *  This function implements the reverse order of strings  */
void reverse(char a[])
{
    
    int i,j,l;
    gets(a);
    i = strlen(a);
    int k=0;
    l = i-1;
    char b[i+1];
    strcpy(b,a);
    for(j=0;j<i;j++)
    {
    
        a[k] = b[l];
        k=k+1;
        l=l-1;
    }  
}

test

Test input
Be honest rather clever.

Output
.revelc rehtar tsenoh eB

原网站

版权声明
本文为[|Light|]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060918542778.html