PRB: R6012 Caused by Error in strtok and strpbrk Example

ID Number: Q66922

6.00 6.00a 6.00ax | 6.00a 6.00

MS-DOS | OS/2

docerr

Summary:

There is an error in the code in the online help example for strtok,

strpbrk, strcspn, and strspn in Microsoft C versions 6.0, 6.0a, and

6.0ax. When compiled with pointer checking turned on in small or

medium model and then run, the following error occurs:

run-time error R6012

- illegal near-pointer use

The error can be eliminated by changing the pointer incrementing in

the vowel count loop from post-increment to pre-increment. For

example, change

/* Count vowels. */

p = string;

count = 0;

do

{

p = strpbrk( p, vowels );

count++;

} while( *(p++) );

to the following:

/* Count vowels. */

p = string;

count = 0;

do

{

p = strpbrk( p, vowels );

count++;

} while( *(++p) ); // <-- Change here...

In this case, the error caught by the pointer checking routine would

not have caused any harm because it would have failed on the last

iteration of the loop.

Additional reference words: token 6.00 6.00a 6.00ax