strlen in a for loop

Has anyone experienced problems using strnlen in a for loop

for( i = 0; i < strlen(buffer); i++)
{…}

We are using this with a pc 104 board and getting occasional errors.

“D Velho” <velhodj@npt.nuwc.navy.mil> wrote in message
news:ae355r$mj3$1@inn.qnx.com

Has anyone experienced problems using strnlen in a for loop

for( i = 0; i < strlen(buffer); i++)
{…}

We are using this with a pc 104 board and getting occasional errors.

try kind of

int len;
len = strlen(buffer);
for ( i = 0; i < len; i++) {

}

// wbr

Unless you are editing “buffer” within the loop and are expecting that to
figure into the comparison, there should be no problem. Remember that the “i
< strlen(buffer)” will be evaluated each loop. If you are changing buffer
but wnat to keep the number of loops constant perhaps the following would
solve your problem:

int buffer_length = 0;

buffer_length = strlen( buffer );

for ( i = 0; i < buffer_length; i++ )
{…}

Hope this helps.

“D Velho” <velhodj@npt.nuwc.navy.mil> wrote in message
news:ae355r$mj3$1@inn.qnx.com

Has anyone experienced problems using strnlen in a for loop

for( i = 0; i < strlen(buffer); i++)
{…}

We are using this with a pc 104 board and getting occasional errors.