Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

char declaration

Status
Not open for further replies.

developer155

Programmer
Jan 21, 2004
512
US
I am trying to declare a char variable like this:
char varname = (char)32;

so basically I need number 32 to become varname of type char (I need to pass it to one string function, replace)

but after declaration when I walk through the code I notice that after declaration varname has value '', instead of '32'.

Am I not declaring it correctly?

thamks!!
 
the char with code 32 is just the space :)
So following three lines are identically equivalent:
char xx = 32;
char xx = '\32';
char xx = ' ';

Ion Filipski
1c.bmp
 
By the way, if you want to make a string which equals to "32" (two characters '3' and '2') you should do like this:

String x = "32";

Ion Filipski
1c.bmp
 
Something is still wrong, I did this: char big = '\32';
and when I walked thru the code I saw that big was assigned this character | instead of 32. What is going on????

thanks!!!
 
It looks a bit strange to me, I've got the same results. Java specifics are a bit different than C++ specifics...

Ion Filipski
1c.bmp
 
char big ='\32' means octal 32, which is = 3*8+2 = 26 in decimal or 1A in hex.

char big ='\u0032' means unicode 32 which is in hex.
 
OK, still having problems: I declared this way:
char big='\u0032';
char small='\u0016';

as you see I need to declare 32 and 16 as char. When I run, program assigns 2 to big (not 32) and | to small (not 16). What I am I doing wrong now??

thanks
 
Because, like Ion Filipski says :
'\u0020" is the space character

'\u0032' is the character '2'

If you need "32" then you need two chars, you can't get it in 1 char :
'\u0033' is the character '3'
'\u0032' is the character '2'

You can find the ascii table at :
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top