Page 1 of 1

PostPosted: Sat Feb 10, 2001 12:37 pm
by Sharpie
How do you reset a char value to nothing?
for example, I have a char variable "test" whose value is 'n'.
When I then say next='';
to reset that to nothing,
I get a compiler error.

PostPosted: Sat Feb 10, 2001 12:47 pm
by ianf
If you post appears correctly then your line next ="; has an error as there should be two double quotes and not one eg:
next = "";
because you are saying that the contents of n is the literal value of "nothing" you need to start and end the literal

PostPosted: Sat Feb 10, 2001 1:44 pm
by Sharpie
Actually it appears wrong, what I was putting was two single quotes. I understand that to set the value of a char variable, one uses single quotes ( like: test = ' value ' ) as opposed to the double quotes used for a string.

PostPosted: Sat Feb 10, 2001 6:29 pm
by airdrik
What you can do is exparament on a new program just setting it to different null values and see what you get (ie. (char)0, "", c=c-c;<img src=icon_smile.gif border=0 align=middle>, etc.)
And pick the best one.

PostPosted: Sat Feb 10, 2001 7:22 pm
by Sharpie
Yep, you're probably right.
If I use "", it compiles, but doesn't work right. I though about trying n=n-n, but didn't actually try it. I will though.

PostPosted: Sun Feb 11, 2001 8:42 am
by Justinespinosa
No need to think. The Charcter 0 is null, 31 is space 27 is ESC, etc... so if you create:

char c;

then do c='a'

the value of c will be 97, i think. If you puts( (int)c ), you will see it.

so just write c = 0, if c is a string c will be "0", but if it's a char, c will be null.


OUTS Softwares

PostPosted: Tue Feb 13, 2001 8:20 am
by guy
If you want to set a char to the null character then set it to '\0' (thats a zero)

char c ;

c = '\0' ;

If you want to set a string to a null string then set it to ""

string s ;

s = "" ;