[NTLUG:Discuss] OT C question

Fred James fredjame at fredjame.cnc.net
Sat Feb 18 00:09:37 CST 2006


All
#include <string.h>
char *strchr(char *S, int c)
returns a pointer to the first occurrence of c in S, or Null if c is not 
found.
If S is "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ1"
and c is T then given
Aptr = strchr(S, c);
then
printf( "%c\n", *Aptr);
will yield T and
printf( "%c\n", *Aptr+1);
will yield U, but
printf( "%c\n", *Aptr+7);
does not yield 1, but rather [ where the ASCII values are (begin snip)
     | 80 P   | 81 Q   | 82 R   | 83 S   | 84 T   | 85 U   | 86 V   | 87 
W   |
     | 88 X   | 89 Y   | 90 Z   | 91 [   | 92 \   | 93 ]   | 94 ^   | 95 
_   |
 (end snip)
so the pointer doesn't seem to be to a position in S, but rather to an 
ASCII value.

Does that seem right, or am I missing something?  Thank you in advance 
for any help you may be able to offer.
Regards
Fred James






More information about the Discuss mailing list