|
|
CBFalconer wrote:
> santosh wrote:
>> CBFalconer wrote:
>>> Tomás Ó hÉilidhe wrote:
>>>> CBFalconer:
>>>>
>>>>>> for ( ; *pc; ++pos, ++pc) *pos = strchr(ascii,*pc) - ascii +
>>>>>> 0x20;
>>>>>>
>>>>>> instead of:
>>>>>>
>>>>>> while (*pc) *pos++ = strchr(ascii,*pc++) - ascii + 0x20;
>>>>>
>>>>> IMO you are making a mistake. The second is simpler, and much
>>>>> easier to detect inaccuracies in. The thing that screams at you
>>>>> is
>>>>> that both are missing copying the terminal '\0'. Both are missing
>>>>> the initialization of pc and pos. Both are missing handling the
>>>>> fact that the char is not found in the ascii string.
>>>>
>>>> They're missing neither of those three things. The context of the
>>>> code is as follows:
>>>>
>>>> static char const ascii[] =
>>>> " !\"#$%&'()*+,-./0123456789:;<=>?@"
>>>> "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>>>> "[\\]^_`"
>>>> "abcdefghijklmnopqrstuvwxyz"
>>>> "{|}~";
>>>>
>>>> for ( ; *pc; ++pos, ++pc)
>>>> *pos = strchr(ascii,*pc) - ascii + ' ';
>>>>
>>>> *pos = 0;
>>>>
>>>> Also, it is assumed that every char is valid ASCII.
>>>
>>> Which is a silly assumption. However, you are still failing to
>>> initialize pc and pos.
>>
>> They are initialised on entry to the function. Please read the
>> previous articles before coming to conclusions.
>
> Don't be silly. I am not going to chase about reading earlier
> posts, which I may or may not have ever received.
The OP does show the complete routine just a few posts up-thread.
|
|