当前位置:网站首页>Pointer -- output all characters in the string in reverse order

Pointer -- output all characters in the string in reverse order

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

requirement

Programming , Enter a string , Output all characters in reverse order .( Use a pointer to achieve )

Code

/* *  This function implements string a Reverse operation of , If the original string is string, Reverse order followed by gnirts, *  Please store the string after reverse order in a In what it points to  */
void reverse(char *a)
{
    
    int n = strlen(a);
    int b[n],c = 0;
    for(int i = n-1;i>=0;i--)
    {
    
        b[c] = a[i];
        c++;
    }
    for(int i = 0;i<n;i++)
    {
    
        a[i] = b[i];
    }   
}

main function

int main()
 {
    
     char a[200];
     gets(a);
     reverse(a);
     puts(a);
    return 0;
 }   

test

Test input
I am a student
Output
tneduts a ma I

原网站

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