-
String reverse function
Hi all,
still workin on my C++ assignment, and I need to reverse a string...
I found a reverse function in the standard string class but I have not found anything useful on how to implement it...
I want to simply change a string "abcd" to "dcba"
Any help or teaching would be welcome...
-
You can reverse a string by using only loops,
for loops.......if you want more help, just tell me......
-
Code:
void strrev(char *in,char *out){
char *buf;
char *t;
int j=0;
int j=0;
j=strlen(in);
if (!j) return;
buf = out;
t = in;
buf +=j + 1;
*buf-- = '\0';
for (i=0;i<j;i++){
*buf-- = *t++;
}
}