Logo

Programming-Idioms

History of Idiom 41 > diff from v5 to v6

Edit summary for version 6 by :

Version 5

2015-08-20, 06:19:07

Version 6

2015-08-20, 10:04:15

Idiom #41 Reverse a string

Create string t containing the same characters as string s, in reverse order.
Original string s must remain unaltered. Each character must be handled correctly regardless its number of bytes in memory.

Idiom #41 Reverse a string

Create string t containing the same characters as string s, in reverse order.
Original string s must remain unaltered. Each character must be handled correctly regardless its number of bytes in memory.

Imports
#include <stdlib.h>
#include <string.h>
Code
int len=strlen(s);
char *t=malloc((len+1)*sizeof(char));
int i;
for(i=0;i<len;i++)
{
	t[i]=s[len-i-1];
}
t[len]=0;