Fred James wrote:

> All
> Thanks to your help I was able to replace
> 
>       for ( i = 0; i < Max; i++ ) {
>               if ( s[i] == S[Sptr] ) {
>                       if ( i == Limit ) {
>                               S[Sptr] = s[0];
>                       }
>                       else {
>                               S[Sptr] = s[i+1];
>                       }
>                       i = Max;
>               }
>       }
> 
> with
> 
>       S[Sptr] = *((strchr(s,S[Sptr]))+1);
> 
> ... where s and S are each a char *, and Sptr is an int.

The latter will blow up (dereference NULL) if S[Sptr] is not in the
string s.  I don't know whether that's an issue in your application.

        char *sloc;
        sloc = strchr(s, S[Sptr]);
        if (sloc)
                S[Sptr] = sloc + 1;  /* N.B. add 1 after comparing to 0 */

Also, the new code doesn't use Max or Limit.  Is that an issue?
If you want to use Max, use strnchr().

        ... strnchr(s, Max, S[Sptr]) ...

-- 
Bob Miller                              K<bob>
                                        [EMAIL PROTECTED]
_______________________________________________
EUGLUG mailing list
[email protected]
http://www.euglug.org/mailman/listinfo/euglug

Reply via email to