Reverse String in C: Quick Guide
One way to reverse the order of characters in a string is to use pointers and loops. The specific code is shown below:
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello, World!";
int len = strlen(str);
for (int i = len - 1; i >= 0; i--) {
printf("%c", str[i]);
}
return 0;
}
In this code, the string length is first obtained using the strlen() function, and then characters are outputted one by one starting from the end of the string, achieving reverse output of the string.