C programming help ....
Rick Bowers
rwbowers at gmail.com
Sun Aug 23 15:37:53 PDT 2009
At 8/23/2009 04:49 PM, Ben Duncan wrote:
>Ok, i have a question for the MORE advanced C programmers.
>
>I want to loop thru a string of characters that may contain some
>"high values", i.e. 0xFF and possible use the & function to test that.
>
>Lets say "^" represents the HIGH value mark and the string looks like this:
>
>ABCDEFG^THIS IS A LONG STRING OF DATA^MORE DATA HERE^1234567890^EOF STRING^\0"
>
>I want to be able to do something like this:
>
>int idx ;
>char MyString [256] ; /* See above string */
>
>for ( idx = 0 ; idx < strlen (MyString) ; idx++
> {
> if ( Mystring[idx} & 0xFF )
> printf ("High value found at: %i ", idx)
> }
>
>
>Is this the correct way to do this ?
>
>Thanks ...
You will want to use 0x80 rather than 0xFF. 0xFF will compare ALL 8
bits while 0x80 will test only the top bit.
You may also want to move the strlen(MyString) "outside" the loop so
it doesn't have to compute it each iteration, e.g.
int idx, len;
for (ix = 0, len = strlen(MyString); idx < len; idx++)
~Rick
More information about the Linux-users
mailing list