0

I am trying to send SMSs using a GSM module with Arduino Mega. I have followed a tutorial and downloaded the SIM908IDE100 library. I am using the function

SendSMS(String&, const char [27]);.

It works fine when I type:

sms.SendSMS("1234567890","Text message");

where "1234567890" is the telephone number I want to send the SMS to and "Text message" is the text of the SMS.

If I instead try to pass to the function a String containing the telephone number

String number = "1234567890"; sms.SendSMS(number,"Text message");

I get the following error:

exit status 1 no matching function for call to 'SMSGSM::SendSMS(String&, const char [27]);'

I don't understand what String followed by an ampersand means. What am I supposed to pass the function as its first argument?

asked Apr 17, 2019 at 17:53
3
  • are you sure it is not the sms.SendSMS("1234567890","Text message"); giving you "no matching function"? Commented Apr 17, 2019 at 17:58
  • @Juraj Yes I am sure. The sms.SendSMS("1234567890","Text message"); works fine and the SMS is sent without any problem. Commented Apr 17, 2019 at 18:26
  • Hint: Try sms.SendSMS(String("1234567890"),"Text message"); Commented Apr 17, 2019 at 18:40

1 Answer 1

0

The function prototype in sms.h is

char SendSMS(char *number_str, char *message_str);

if number is String, you should have

sms.SendSMS((char*) number.c_str(),"Text message");

c_str() is a function of the Strinng class. It returns a pointer to internal char array of the String object.

The cast to char* is necessary because the author of the library didn't make the parameter constant with const char*. (It is a good practice, to declare pointers and references as constants.)

The error message no matching function for call to 'SMSGSM::SendSMS(String&, const char [27]); shows the arguments you try to use. String& is reference to some instance of the String type

answered Apr 17, 2019 at 18:48
4
  • if I use sms.SendSMS(number.c_str(),"Text message"); I get the error: no matching function for call to 'SendSMS(const char*, const char [13])' Commented Apr 17, 2019 at 19:42
  • sms.SendSMS((char*) number.c_str(),"Text message"); Commented Apr 17, 2019 at 19:54
  • thank you very much, it works now. I still don't fully understand how (char*) works, would you mind to briefly explain it? thanks again Commented Apr 17, 2019 at 20:12
  • tutorialspoint.com/cprogramming/c_strings.htm Commented Apr 18, 2019 at 4:56

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.