reverse a string in C
#include <stdlib.h>
#include <string.h>
#include <assert.h>
char* reverse(char* s) {
assert(s!=NULL);
char *r = (char*)strdup(s);
int len = strlen(s);
if(r==NULL) {
return NULL;
}
while(--len) {
*(r+len) = *s;
s++;
}
*r = *s;
return r;
}