C - How to Reverse String?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| #include <stdio.h>
#include <string.h>
void reverse(char* str)
{
int i, j;
char c;
for(i = 0, j = strlen(str)-1; i<j; ++i, --j)
c = str[i], str[i] = str[j], str[j] = c;
}
int main()
{
char str[] = "ABCDE";
reverse(str);
puts(str);
return 0;
}
|