title: How to make SoftwareSerial variable available in a function in arduino
body: <p>I am trying to make use of a SoftwareSerial variable in a function, but for some reason it is always unavailable.
  The various codes are given below.</p>
  
  <pre><code>gsm.h
  
  #ifndef GSM_H_
  #define GSM_H_
  #include &lt;SoftwareSerial.h&gt;
  
  struct gsm{
  
      char *message;
      char phone_number[20];
  
      void getText(SoftwareSerial serial, int index);
  };
  
  
  #endif
  
  
  gsm.cpp
  
  #include "gsm.h"
  #include &lt;string.h&gt;
  #include &lt;arduino.h&gt;
  #include &lt;SoftwareSerial.h&gt;
  
  void gsm::getText(SoftwareSerial serial, int index){
  
      char str[100];
      serial.print("AT+CMGR=1 \r");
      delay(250);
      if(serial.available()){
         Serial.print("serial is available");
         serial.readBytes(message, 100);
      }
  
  }
  
  
  test.ino
  
  #include "gsm.h"
  #include &lt;SoftwareSerial.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdio.h&gt;
  
  SoftwareSerial mySerial(10, 11); // RX, TX
  
  gsm gm;
  
  void setup(){
  
     Serial.begin(9600);
     mySerial.begin(9600);
     gm.getText(mySerial,1);
     Serial.print(gm.message);
  }
  
  void loop(){
  
  }
  </code></pre>
  
  <p><strong>Serial.print(gm.message)</strong> is supposed to return what has been copied into message by <strong>serial.readBytes(message,100)</strong>. 
  But it seems the test for serial availability failed as the code inside <strong>if(serial.available())</strong> don't get executed. Please i need help as i have been battling with this for some time now.</p>