How to reset char to null?

Discuss PocketC for CE (including Desktop Edition)

Postby Sharpie on Sat Feb 10, 2001 12:37 pm

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.
Posts: 3
Joined: Sat Feb 10, 2001 12:32 pm

Postby ianf on Sat Feb 10, 2001 12:47 pm

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
Posts: 92
Joined: Mon Dec 11, 2000 7:25 am
Location: United Kingdom

Postby Sharpie on Sat Feb 10, 2001 1:44 pm

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.
Posts: 3
Joined: Sat Feb 10, 2001 12:32 pm

Postby airdrik on Sat Feb 10, 2001 6:29 pm

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.
Posts: 26
Joined: Fri Feb 09, 2001 3:25 pm

Postby Sharpie on Sat Feb 10, 2001 7:22 pm

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.
Posts: 3
Joined: Sat Feb 10, 2001 12:32 pm

Postby Justinespinosa on Sun Feb 11, 2001 8:42 am

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

OUTS Softwares
Posts: 156
Joined: Wed Dec 06, 2000 2:30 pm
Location: Switzerland

Postby guy on Tue Feb 13, 2001 8:20 am

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 = "" ;

PocketC CE API interface:
PCForm and CE API forum:
Posts: 879
Joined: Thu Dec 07, 2000 8:58 am
Location: United Kingdom

Return to PocketC for CE

Who is online

Users browsing this forum: No registered users and 4 guests