[opensuse] Another slightly OT c question, howto handle extended ascii chars? >127



Listmates,

I'm parsing output that has the degree symbol in it in c. The character code
for the symbol is 167, but of course the ascii character set it limited to
0-127. Believe it or not, using a cut-n-paste into the strtok delimiter set
works, but that just feels like a cludge. Example:

const char delimiters[] = " +°,;:!-";
<snip 1st call to strtok>
token = strtok (NULL, delimiters);

Will break the string on ° correctly. But looking at how c is handling this
clude causes concern:

for (i=0;i<strlen(delimiters);i++) {
printf("%c %d\n", delimiters[i],delimiters[i]);
}

Yields:

32
+ 43
� -62
� -80
, 44
; 59
: 58
! 33
- 45

Hmm, any time I see the little � character, that's a bad sign. So, is there
any trick to handling the chars that are outside of the normal ascii chars,
but we seem to run into all the time? Is this the area of the thinly defined
wchar_t?

--
David C. Rankin, J.D.,P.E.
Rankin Law Firm, PLLC
510 Ochiltree Street
Nacogdoches, Texas 75961
Telephone: (936) 715-9333
Facsimile: (936) 715-9339
www.rankinlawfirm.com
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx



Relevant Pages

  • Re: Free memory cause segmentation fault.
    ... Have you read and understood the operation of the strtok() function? ... Are you aware that it overwrites the character terminating each token ... and you will allocate 5 bytes for ... Writing past the end of allocated memory produces undefined behavior, ...
    (comp.lang.c)
  • Re: Why occur the mistake in runtime about strtok()?
    ... The strtok() can overwrite *p1? ... which is delimited by a character from the string pointed to ... If no such character is found, then there are no tokens in ... searches for a token will return a null pointer. ...
    (comp.lang.c)
  • Re: splitting two arrays.
    ... against (in this example, the character pair //). ... Before i send my original string to the funtion, it has, lets supose, ... Read the manual page for strtok, carefully - one of its foibles ...
    (comp.lang.c)
  • Re: use of strtok( )
    ... to strtok. ... The second argument is a list of delimiter characters - any one of ... null character, strtok has a note of the location of the third "?" ... On this call, as the first argument is a NULL pointer, strtok ...
    (comp.lang.c)
  • Re: strtok() and EOL
    ... > Am I using strtok incorrectly? ... Are you perhaps opening your file in binary mode? ... some OS's store newline as more than one character in text files. ... E.g. Windows uses CR/LF pair and typical Windows C implementations ...
    (comp.lang.c)