View unanswered posts | View active topics It is currently Fri Oct 31, 2014 12:02 am






Reply to topic  [ 3 posts ] 
1.45: unexpected error converting short to string 
Author Message
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 1.45: unexpected error converting short to string
hi,
what's wrong with the following code?

I have a converting function (shortValue to String)

if I write
Code:
string Color2String(short color)

I get the error message "Invalid function return type."

and if I write
Code:
void Color2String(short color; &string sbuf)

I get the error message "Unexpected scanner token-> '&' "

I can't find the mistake :?

this is the code (although it's for a color sensor, the problem is actually more related to a general RobotC function programming problem than to the sensor, so I post it here):

Code:

void Color2String(short color; &string sbuf)
{

    if (color==0) sbuf="black";
    else
    if (color==1) sbuf="violet";
    else
    if (color==2) sbuf="blue";
    else
    if (color==3) sbuf="cyan";
    else
    if (color==4) sbuf="green";
    else
    if (color==5) sbuf="YeGreen";
    else
    if (color==6) sbuf="yellow";
    else
    if (color==7) sbuf="orange";
    else
    if (color==8) sbuf="red";
    else
    if (color==9) sbuf="magenta";
    else
    if (color==10) sbuf="pink";
    else
    if (color==11) sbuf="lViolet";
    else
    if (color==12) sbuf="lCyan";
    else
    if (color==13) sbuf="lYellow";
    else
    if (color==14) sbuf="lOrange";
    else
    if (color==15) sbuf="lRed";
    else
    if (color==16) sbuf="lPink";
    else
    if (color==17) sbuf="white";

}

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Fri Nov 14, 2008 2:19 pm, edited 1 time in total.



Fri Nov 14, 2008 8:14 am
Profile
Rookie
User avatar

Joined: Thu Jun 26, 2008 11:27 am
Posts: 21
Location: Johannesburg, South Africa
Post Re: 1.45: unexpected error converting short to string
Hi

You must be having a bad day.

First you have a semi-colon instead of a comma after 'color' and then it should be 'string &sbuf' rather than '&string sbuf'

Cheers


Fri Nov 14, 2008 11:34 am
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.45: unexpected error converting short to string
yes, you're probably right.
and especially comma and semicolon always are a problem since I changed form Pascal/Delphi to C.
The same it's with "int &vname"(C) and "var int vname(Pascal)" :oops:

But now it runs fine. thx 4 your help!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Fri Nov 14, 2008 2:25 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.