C language string reverse order

The following is the reverse order of a string, see the code

#include <stdio.h>
#include <string.h>
#include <memory.h>
void str_reverse(char* buff)
{
    
    
    char* start = buff;
    char* end = start + strlen(buff) - 1;
    while (start < end) {
    
    
        *start ^= *end;
        *end ^= *start;
        *start ^= *end;
        start++;
        end--;
    }
}
int main(int argc, char *argv[])
{
    
    
	char str[20] = "hello world!";
    str_reverse(str);
    printf("%s\n", str);
}


Guess you like

Origin blog.csdn.net/cp_srd/article/details/104279054