Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

Inside my main loop there is this string:

String string1;

I have a function that will take string1 as parameter, and use it to send this string as SMS.

sendSMS(string1);

This is the sendSMS() function (without parameters):

void sendSMS()
{ sms.beginSMS(remoteNumber);
  sms.print(finalstr);
  sms.endSMS();
  lcd.setCursor(0, 0);
  lcd.print("Message sent!");
  delay(10000); 
}

My questions are:

  1. How do I put the string input parameter in sendSMS?
  2. Do I also need to use a function prototype for sendSMS()? (so that it appears three times, 1 in the prototype, 1 in the declaration and one in the call). Or I don't need to use function prototype before the main loop()?
share|improve this question

1 Answer 1

  1. Just change

    void sendSMS()
    

    to

    void sendSMS(String thisIsAString)
    

    You can then access the parameter inside the function with thisIsAString.

  2. No, you do not need a prototype.

share|improve this answer
1  
I would rather advise to pass the String by reference, to avoid additional code to be executed for nothing (copy-constructor, destructor): void sendSMS(String& thisIsAString) or even better, a const reference, if the string argument is not to be modified by the function: void sendSMS(const String& thisIsAString) –  jfpoilpret Jun 24 '14 at 17:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.