Go Down

Topic: How to pass a variable to a function? (Read 2060 times) previous topic - next topic

tuxduino

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

Lakes

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: [Select]
/*
   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);               
}

PeterH


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.
I only provide help via the forum - please do not contact me for private consultancy.

Lakes

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:


PaulS

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.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy