Bonkers

Andy Armstrong andy at hexten.net
Fri May 11 00:04:42 BST 2007


On 10 May 2007, at 23:46, Nicholas Clark wrote:

> On Thu, May 10, 2007 at 11:22:46PM +0100, Ash Berlin wrote:
>
>> ISTR my solution to that exact question was:
>>
>> include <stdio.h>
>> include <stdlib.h>
>>
>> char* reverse(char* str) {
>>   int i, len = strlen(str), len_2 = len/2;
>>
>>   for (i=0; i < len_2; i++) {
>>     char s = str[i];
>>     str[i] = str[len-1-i];
>>     str[len-1-i] = s;
>>
>>   }
>> }
>
> I think that yours breaks on an empty string.

I don't think it does. The loop never executes if len is zero.

I think it breaks by claiming to return a char * but then being void.

-- 
Andy Armstrong, hexten.net



More information about the london.pm mailing list