How to compare array?

how to compare char storage1[100] with char storage2[100]? like if storage1 is greater than storage2, do this thing. How should I do it?

if( char storage1 > char storage2)
delay(1000)
else
delay(2000)

??? Maybe?

Look at the toggleredled part in this link

http://www.gammon.com.au/forum/?id=11411

What do you mean by 'greater than' in the context of arrays ?

^ yes. or it can be like if I have storage[100] then I put a greater than 100 in the storage then do this thing. like that?

Maybe if you can give a little more info on what your trying to do you will get more help.

heres what im planning to do.

char smsdata[160];

if(gsm.readSMS(smsdata, 160, numberRx, 20))
{
  if (smsdata received over 160 length message)
   {
     sms.SendSMS(numberRx, "Sorry, message maximum limit exceed.");
   }
}

if (smsdata > 160)
{
sms.SendSMS(numberRx, "Sorry, message maximum limit exceed.");
}

maybe? I'm not sure. Trying to read about how chars are stored.

^ that wont work. your comparing a pointer and integer.

Seems to me that you're trying to measure the length of the string you read back from the modem. The function strlen() returns the number of characters in a string.

like this Sir? thank you.

char smsdata[160];

if(gsm.readSMS(smsdata, 160, numberRx, 20))
{
  if (strlen(smsdata) > 160)
   {
     sms.SendSMS(numberRx, "Sorry, message maximum limit exceed.");
   }
}

Will you/can you ever get a text message longer than 160 characters ?

If you can, then your program is already likely to crash because there will be more than the expected number of characters in the smsdata array and the extra characters will have written over something else.

What library are you using ?
If it is the gsm library then this seems relevant

  • readSMS (char* msg, int msglength, char* number, int nlength) Checks if there are available messages. Takes the first one and deletes it from modem memory. Returns message in msg, and original phone number in “number”. Msglength and nlength must hold the corresponding buffer size.

It seems to indicate that the second parameter limits the number of characters read from the message.

Seeing your whole code as it is at the moment would help a lot

im using the library from open-electronics the GSMGPRS shield library.

boolean SIMCOM900::readSMS(char* msg, int msglength, char* number, int nlength)
{
  long index;
  /*
  if (getStatus()==IDLE)
    return false;
  */
  _tf.setTimeout(_GSM_DATA_TOUT_);
  //_cell.flush();
  _cell << "AT+CMGL=\"REC UNREAD\",0" << endl;  // change the 1 to 0 to make the unread to read
  if(_tf.find("+CMGL: "))
  {
    index=_tf.getValue();
    _tf.getString("\"+", "\"", number, nlength);
    _tf.getString("\n", "\nOK", msg, msglength);
    _cell << "AT+CMGD=" << index << ",3" << endl; // added  3 next to index to delete read and sent messages.
    _tf.find("OK");
    return true;
  };
  return false;
};

I tried making the message length to 200 it still accept 160 and no errors, it only cuts the exceeded message.

jepoy12:
like this Sir? thank you.

char smsdata[160];

if(gsm.readSMS(smsdata, 160, numberRx, 20))
{
  if (strlen(smsdata) > 160)
   {
     sms.SendSMS(numberRx, "Sorry, message maximum limit exceed.");
   }
}

Well, yes, but there's not much point comparing the string length to the size of the buffer it is in. If the length exceeds the size of the buffer, it's already too late. I'm not familiar with the GSM library you're using there but it seems to have support for limiting the length of messages it supplies. You need to look at that API to see how oversize messages are intended to be handled.