combine GPS with GSM

I work with GSM shield sim900 with u-blox GPS sheiled and i could not join two codes with each other to send a location via sms
the gps code is:

//at 9600 bps 8-N-1
//Computer is connected to Arduino/Crowduino
//SoftSerial Shield is connected to the Software UART:D2&D3 
#include <SoftwareSerial.h>
SoftwareSerial SoftSerial(6, 7);
unsigned char buffer[256]; // buffer array for data recieve over serial port
int count=0;     // counter for buffer array 
void setup()
  SoftSerial.begin(9600);               // the SoftSerial baud rate   
  Serial.begin(9600);             // the Serial port of Arduino baud rate.
void loop()
  if (SoftSerial.available())              // if date is comming from softwareserial port ==> data is comming from SoftSerial shield
    while(SoftSerial.available())          // reading data into char array 
      buffer[count++];     // writing data into array
      if(count == 256)break;
    Serial.write(buffer,count);            // if no data transmission ends, write buffer to hardware serial port
    clearBufferArray();              // call clearBufferArray function to clear the storaged data from the array
    count = 0;                       // set counter of while loop to zero
  if (Serial.available())            // if data is available on hardwareserial port ==> data is comming from PC or notebook
    SoftSerial.write(;       // write it to the SoftSerial shield
void clearBufferArray()              // function to clear buffer array
  for (int i=0; i<count;i++)
    { buffer[i]=NULL;}                  // clear all index of array with command NULL
and the GSM code is:

#include "SIM900.h"
#include <SoftwareSerial.h>
//If not used, is better to exclude the HTTP library,
//for RAM saving.
//If your sketch reboots itself proprably you have finished,
//your memory available.
//#include "inetGSM.h"

//If you want to use the Arduino functions to manage SMS, uncomment the lines below.
#include "sms.h"

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//this code is based on the example of Arduino Labs.

//Simple sketch to send and receive SMS.

int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];

//debug begin
char sms_position;
char phone_number[20]; // array for the phone number string
char sms_text[100];
int i;
//debug end

void setup()
    //Serial connection.
    Serial.println("GSM Shield testing.");
    //Start configuration of shield with baudrate.
    //For http uses is raccomanded to use 4800 or slower.
    if (gsm.begin(4800)) 

        //Enable this two lines if you want to send an SMS.
        if (sms.SendSMS("0795647528", "Arduino SMS"))
        Serial.println("\nSMS sent OK");
       //if NO SPACE ,you need delte SMS  from position 1 to position 20
       //please enable this four lines

void loop()
        //Read if there are messages on SIM card and print them.
        if (sms_position) 
            // read new SMS
            Serial.print("SMS postion:");
            sms.GetSMS(sms_position, phone_number, sms_text, 100);
            // now we have phone number string in phone_num
            // and SMS text in sms_text
            Serial.println("NO NEW SMS,WAITTING");

First of all you need to read up on the limitations when using two instances of SoftwareSerial.

Second, GrumpyMike has published a guide to combining two sketches:

Good luck!