NO

Author Topic: escape sequence in a string  (Read 173 times)

Offline jamiebreeze

  • Member
  • *
  • Posts: 2
escape sequence in a string
« on: October 02, 2019, 10:10:25 am »
Can anyone help me about the following code? The result i got is wierd
Code: [Select]
#include <stdio.h>

int main(int argc, char *argv[])
{
unsigned char *p;
p = "\xA0\xFF";
printf("%x, %x\n", *p, *(p+1));

    return 0;
}


Offline bitcoin

  • Member
  • *
  • Posts: 70
Re: escape sequence in a string
« Reply #1 on: October 03, 2019, 01:32:32 pm »
What do you want?

Offline jamiebreeze

  • Member
  • *
  • Posts: 2
Re: escape sequence in a string
« Reply #2 on: October 03, 2019, 04:56:33 pm »
I supposed the result would be "a0, ff", but "3f, 3f" is what i get, seems abnormal?
« Last Edit: October 03, 2019, 05:19:38 pm by jamiebreeze »

Offline John S. Kent

  • Member
  • *
  • Posts: 4
Re: escape sequence in a string
« Reply #3 on: October 04, 2019, 01:32:25 am »
You are trying to put 2 characters in a single character.  Assuming ASCII encoding, 0xA0 has a character with no glyph. 0xFF has the glyph that has 2 dots over a 'ΓΏ'. The display value 0x3f has the glyph '?'.

My guess is that compiler is trying to tell you that it can't display what you are asking for.

All this has to do with language localization & character sets being used.  You need to read about the c Standard closely for how c handles language encoding differences. Actually a complex subject.

This is my 1st posting on the form. I hope this is helpful; otherwise my apologies.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1866
Re: escape sequence in a string
« Reply #4 on: October 04, 2019, 10:50:27 am »
what Pelles C version, 9 ?
as 3fh is '?', what is your language/ codepage ?

for me it works.
Code: [Select]
unsigned char *p = (unsigned char *)"\xA0\xFF";give us a zipped project or just an object file, if it still fails.

optimized version don't even create string, just put parameters
Code: [Select]
_main:
  [00000000] 68FF000000             push              FF
  [00000005] 68A0000000             push              A0
  [0000000A] 6800000000             push              @9
  [0000000F] E800000000             call              _printf
EDIT:
using ntleas
Code: [Select]
Building test_ch.obj.
C:\code\PellesC\_Forum\test_ch.c(6): warning #2223: Unable to convert character '\u00a0' to codepage 932; using default character.
C:\code\PellesC\_Forum\test_ch.c(6): warning #2223: Unable to convert character '\u00ff' to codepage 932; using default character.
Done.
Code: [Select]
_main:
  [00000000] 6A3F                   push              3F
  [00000002] 6A3F                   push              3F
  [00000004] 6800000000             push              @11
  [00000009] E800000000             call              _printf
  [0000000E] 83C40C                 add               esp,C
  [00000011] 31C0                   xor               eax,eax
  [00000013] C3                     ret               

another way to do byte array
Code: [Select]
unsigned char s[] = {0xA0,0xFF,0};
test ntleas.exe with test_ch.c
A is App parameters
Code: [Select]
x64\ntleas.exe pocc.exe Atest_ch.c
« Last Edit: October 07, 2019, 01:01:22 pm by TimoVJL »
May the source be with you

Offline jamiebreeze

  • Member
  • *
  • Posts: 2
Re: escape sequence in a string
« Reply #5 on: October 06, 2019, 05:21:46 pm »
Thank you to John and TimoVJL, but the problem still exists.
My system language is Chinese, but for 'codepage', I dont know?
I've tried several hex values to figure out why, and no matter which value I used, once it's big enough, it will be '3f'.
I'm going to test my orignal code on another computer to confirm the version problem (oh yes mine is Pelles C 9.00.9 installed on a Win10-64bit system).
Thank you again Timo for trying my codes on your machine.

Offline John S. Kent

  • Member
  • *
  • Posts: 4
Re: escape sequence in a string
« Reply #6 on: Yesterday at 06:00:52 am »
I only know English. So I can only give advice for an
English Windows environment.

The Code Page can be set in Windows from the Control Panel.
Select "Region & Language"
Select the "Advanced" tab of the dialog.
In the "Language for non-Unicode programs" frame
Select the Change System Local.
The selection you make is the "Code Page"
I see 5 selectable Code Pages.
Undoubtedly 1 of these is selected.

This is just the beginning.

You will need to read extensively about UNICODE & Wide-character handling in
the c language.  The are several data types & many functions specific to these
in the c language. This is well beyond my experience.

Offline John S. Kent

  • Member
  • *
  • Posts: 4
Re: escape sequence in a string
« Reply #7 on: Yesterday at 06:09:22 am »
I said: I see 5 selectable Code Pages.
I should have said  I see 5 select-able Code Pages for Chinese
You would have choose the correct region for you.