itsanjan / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Function that return a char array or a string function #655

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. I create a string function that return a String object or an char array 

2.If I write it and I don't call it, it is compiled without errors instead I 
call it inside the loop this is the output

sketch_sep26a.cpp: In function 'void loop()':
sketch_sep26a:15: error: 'LightStateRange' cannot be used as a function

3. This is the entire code 
--------------------------------------
void setup() {
  Serial.begin(9600); // initializa output to pc 

}

void loop(){
char  LightStateRange[]="";
String _l="";
_l= LightStateRange(30);
Serial.println(_l.length());

}

String  LightStateRange(int light){

String  _lightState="";
 /* 0-25 Dark 
   26-70 Dark with moon
   71-140 Night with near civil light
   140- 300 Early morning or became night
   300 - 500 morning or afternoon
   501- 800 light
   800  bright
   900  very bright
   */
   /*
   if (light==0 || light<=25 )    _lightState="Dark";
   if (light>=25 || light<=70 )   _lightState="Dark with moon ";
   if (light>=71 || light<=140 )  _lightState="Night with near civil light";
   if (light>=140 || light<=300 ) _lightState="Early morning or becaming night";
   if (light>=301 || light<=500 ) _lightState="Morning or afternoon";
   if (light>=501 || light<=800 ) _lightState="Day and light";
   if (light>=801 || light<=900 ) _lightState="Bright";
   if (light>=901  )              _lightState=" Very Bright";
   */
  return _lightState;

}
----------------------------------------------------------

What is the expected output? What do you see instead?

What version of the Arduino software are you using?  0022
On what operating system? Windows Xp
  Which Arduino board are you using? Arduino uno

Please May you explain why?
Best regards

Original issue reported on code.google.com by raul...@gmail.com on 26 Sep 2011 at 12:42

GoogleCodeExporter commented 8 years ago
You have a variable called "LightStateRange" and a function called the same. 
Use different names.

Original comment by ulrich.moritz on 27 Sep 2011 at 12:43

GoogleCodeExporter commented 8 years ago
You should probably ask about this in the forum, as I think it's more of a 
programming question than a bug.  But if there is a bug, here, please open a 
new issue so we can fix it.

Original comment by dmel...@gmail.com on 27 Sep 2011 at 9:25

GoogleCodeExporter commented 8 years ago
Thanks for the help and sorry a for the mistake
Best regards

Original comment by raul...@gmail.com on 28 Sep 2011 at 8:42

GoogleCodeExporter commented 8 years ago
Don't write functions to "return an array."

Write functions that can fill out a given array. 
Remember to tell the function how long the array is.

Original comment by mahmoudz...@gmail.com on 23 Jan 2013 at 11:44