Pages: 1 [2]   Go Down
Author Topic: How to pass a variable to a function?  (Read 1564 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You didn't really read the page I linked earlier, did you ?
Logged

Offline Offline
Sr. Member
****
Karma: 6
Posts: 429
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So to pass an array (pointer?) name, you have to put a the "star" character in front of it.
I think that what its doing anyway...

Should it be added to this?
http://www.arduino.cc/en/Reference/FunctionDeclaration

Code:
/*
   Demo Code for passing Array (pointer?) to function
*/
byte inByte[] = {240, 240, 240 ,240, 240, 199, 23, 1, 1, 8, 49, 48, 49, 48, 51, 51, 48, 10, 0, 49, 50, 51, 52, 53};
int counter = 0;
int bufferLength = 23;

void setup() {
 
  Serial.begin(1200);
  Serial.println("Serial Connected");
}

void loop() {     
     //Print some Labels
      Serial.println("INDEX \t \t DEC \t \t ASCII");
      byte Buffer[bufferLength];
      char StringBuffer[bufferLength];
      for (int x= 0; x < bufferLength; x++)
      {
        Buffer[x] = inByte[x];
        Serial.print(x);
        Serial.print("\t \t");     //print a tab
        Serial.print(Buffer[x]);
        Serial.print("\t \t");     //print a tab         
        StringBuffer[x] = Buffer[x];
        Serial.println(StringBuffer[x]);
        } //EndFor
       
     getDateTime(StringBuffer);
               
 delay(10000); 
} //End Loop 

void getDateTime(char *StringBuffer)
{
        //Extract Date and Time from stringbuffer (which is of type char)
      char timeBuffer[12];
      for (int x = 0; x < 10 ; x++)
      {
        timeBuffer[x] = StringBuffer[x + 10];
      }
      Serial.println("");
      Serial.print("timeBuffer printed output is  ");   
      Serial.println(timeBuffer);               
}
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So to pass an array (pointer?) name, you have to put a the "star" character in front of it.

No. To declare that something is a pointer, you put a star '*' in front of the variable name in the declaration. That's what's happening in those function declarations.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Sr. Member
****
Karma: 6
Posts: 429
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.cplusplus.com/doc/tutorial/pointers/
 smiley-eek  dealing with pointers is why I`ve avoided "C" type programming until now, gives me a headache!:smiley-mr-green:

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 642
Posts: 50423
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
dealing with pointers is why I`ve avoided "C" type programming until now, gives me a headache
But, once you understand them, they are so useful and easy that you'll wonder why you ever had trouble.
Logged

Pages: 1 [2]   Go Up
Jump to: