Bob Miller wrote:
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
That is true ... a little more detail ... s represents the list of
allowable characters for this application, and there is a function (call
it function A) that insures the S contains only allowable characters
before it is presented to the function (call it function B) that
contains this line of code. Function A is called only once, and
function B potentially many times. Max and Limit were necessary to
"walk" through s, but we are only incrementing one character, at one
subscript (position) in S in this operation - the final version does
that neatly enough.
Regards
Fred James
_______________________________________________
EUGLUG mailing list
[email protected]
http://www.euglug.org/mailman/listinfo/euglug