Re: Highly efficient string reversal code
On Sep 26, 4:56 pm, "Rosario" <x...@y.zwrot e:
The length of a string won't be a negative. The cast also isn't
required. The rest of it seems fine :)
On Sep 26, 4:56 pm, "Rosario" <x...@y.zwrot e:
>
unsigned my_strrev(char *s)
{unsigned h;
char *e, t;
if(s==0) return 0;
h=strlen(s);
if((int)h<=0) return 0;
e=s+h-1;
for( ;e>s ;--e,++s)
{t=*s; *s=*e; *e=t;}
return h;
>
}
>
not tested
don't know if "if((int)h< =0) return 0;" is right
>
unsigned my_strrev(char *s)
{unsigned h;
char *e, t;
if(s==0) return 0;
h=strlen(s);
if((int)h<=0) return 0;
e=s+h-1;
for( ;e>s ;--e,++s)
{t=*s; *s=*e; *e=t;}
return h;
>
}
>
not tested
don't know if "if((int)h< =0) return 0;" is right
>
required. The rest of it seems fine :)
Comment