Pelles C forum

C language => Beginner questions => Topic started by: twh_twh on May 22, 2012, 05:20:07 PM

Title: The answer does not match with the book (C Primer Plus)
Post by: twh_twh on May 22, 2012, 05:20:07 PM
#include <stdio.h>
int main(void)
{
  unsigned char a;
  char b;
  a = '\376';
  b = a;
  printf("%d,%d",a,b);
  return 0;
}
The answer is the book :254,-2
In pelles c:63,63 why?
Title: Re: The answer does not match with the book (C Primer Plus)
Post by: CommonTater on May 22, 2012, 05:53:19 PM
You should not post stuff like this as a bug report... Pelle is way too busy to ask him to weed through this kind of problem.

Look in your project options on the compiler tab... is "Char type is unsigned" checked? 
If so uncheck it; your b variable is a signed character.

For what it's worth...
Title: Re: The answer does not match with the book (C Primer Plus)
Post by: twh_twh on May 22, 2012, 07:13:21 PM
warning #2223: Unable to convert character '\u00fe' to codepage 936; using default character.

why?
Title: Re: The answer does not match with the book (C Primer Plus)
Post by: Stefan Pendl on May 22, 2012, 11:34:25 PM
The problem here seems to be the regional settings of your system, which seem to be for an Asian language.
Title: Re: The answer does not match with the book (C Primer Plus)
Post by: CommonTater on May 23, 2012, 03:16:17 AM
For what it's worth...  http://msdn.microsoft.com/en-US/goglobal/cc305153

Apparently \376 = 0xFe = 254, doesn't map to any character on that code page.




Title: Re: The answer does not match with the book (C Primer Plus)
Post by: twh_twh on May 23, 2012, 03:47:32 AM
Thank you very much!!