Read/Write to EEPROM using AVR/EEPROM.h (SOLVED)

I am new to programming and have been experimenting using examples and code shared by others. I am trying to Read/Write to EEPROM using AVR/EEPROM.h library and eeprom_read_block/eeprom_write_block. My current project utilizes the GSM shield to send receive SMS. I want to store the phone number of an incoming SMS in certain cases and utilize in other sections of code. I wrote a sketch to test the capabilities. It compiles but does not produce intended results. The phone number prints out as yyyyyyyyyyyyyyyyyyyy. Any help is appreciated. Here is the sketch

*/

// include the GSM library
#include <GSM.h>
#include <avr/eeprom.h>
// PIN Number for the SIM
#define PINNUMBER ""
#define NUM_MAX 20

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

// Array to hold the number a SMS is retreived from
char senderNumber[NUM_MAX];  
//Array to define the number to send all SMS alerts
char smsNum[NUM_MAX];
//save location
char  save[NUM_MAX];


void setup() 
{
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  } 

  Serial.println("SMS Messages Receiver");
    
  // connection state
  boolean notConnected = true;
  
  // Start GSM connection
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }
  
  Serial.println("GSM initialized");
  delay(60000);
  sms.flush();
  Serial.println("All Messages Deleted");
  Serial.println("Waiting for messages");
}

void loop() 
{
  char c;
  
  // If there are any SMSs available()  
  if (sms.available())
  {
    Serial.println("Message received from:");
    
    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);
    
   if (millis() < (300000)){
   char *smsNum = senderNumber;
   eeprom_write_block(save, smsNum, NUM_MAX);
   Serial.print("SMS Number change accepted -"); 
   eeprom_read_block(smsNum, save, NUM_MAX);
   Serial.println(smsNum);
   Serial.print("Sending Confirmation SMS");
   sms.beginSMS(smsNum);
   sms.print("Your phone will receive SMS alerts for this device");
   sms.endSMS();
   
   
   }
    else{
    Serial.println("sms number change locked");
    eeprom_read_block(smsNum, save, NUM_MAX);
    Serial.print("SMS Number is -"); 
    eeprom_read_block(smsNum, save, NUM_MAX);
    Serial.println(smsNum);
    }

    // Read message bytes and print them
    while(c=sms.read())
      Serial.print(c);
      
    Serial.println("\nEND OF MESSAGE");
    
    //Delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
    
    Serial.println("\nCOMPLETE!\n");
  }

  delay(1000);

}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

The value 'y' you're seeing is actually the serial monitor's attempt to print the ascii code 255, which is the value you get when you read from uninitialised EEPROM.

Your calls to eeprom_write_block() and eeprom_read_block() don't look right to me - I'm not familiar with that library but I would expect the destination address to be an EEPROM offset not the address of a variable in SRAM. I can't say for sure without knowing what that library does, but I suspect you will have more success if you specify the EEPROM address as zero (i.e. writing to / reading from the first locations in EEPROM). In any case, the address of a variable in SRAM does not seem correct for you to specify as an EEPROM address.

Do be careful that your sketch can't write to the EEPROM very frequently because the EEPROM has a limited life and can be worn out quite quickly if a bug in your sketch causes it to write repeatedly.

Two things. First, the call to eeprom_write_block() has the source and destination variables reversed. Second, the eeprom functions expect the address of a variable in EEPROM as the destination for write, or as the source for read. The variable "save" is just a regular array in SRAM, just like smsNum. To define a variable or array in EEPROM, use the EEMEM attribute. Below is a stripped down example without the GSM stuff.

#include <avr/eeprom.h>

#define NUM_MAX 20

char smsNum1[NUM_MAX];       //an array in SRAM
char smsNum2[NUM_MAX];       //another array in SRAM
char EEMEM save[NUM_MAX];    //an array in EEPROM

void setup(void)
{
    // initialize serial communications and wait for port to open:
    Serial.begin(9600);
    while (!Serial) {
        ; // wait for serial port to connect. Needed for Leonardo only
    } 

    strcpy(smsNum1, "Hello, world!");
    eeprom_write_block(smsNum1, save, NUM_MAX);
    eeprom_read_block(smsNum2, save, NUM_MAX);
    Serial.println(smsNum2);
}

void loop(void)
{
}

Jack/Peter.....Thanks for the help! I have run the sketch provided and works as expected. I will now try modifying my original sketch and go from there. I appreciate the quick responses

This issue is now resolved. Here is the sketch that includes Jack's suggested modifications. Thanks again Jack!

*/

// include the GSM library
#include <GSM.h>
#include <avr/eeprom.h>
// PIN Number for the SIM
#define PINNUMBER ""
#define NUM_MAX 20

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

// Array to hold the number a SMS is retreived from
char smsNum1[NUM_MAX];
//Array to define the number to send all SMS alerts
char smsNum2[NUM_MAX];
//Array in EEPROM
char EEMEM save[NUM_MAX];
//Array to hold incoming sms number
char senderNum[NUM_MAX];

void setup()
{
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

Serial.println("SMS Messages Receiver");

// connection state
boolean notConnected = true;

// Start GSM connection
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}

Serial.println("GSM initialized");
delay(60000);
sms.flush();
Serial.println("All Messages Deleted");
Serial.println("Waiting for messages");
eeprom_read_block(smsNum2, save, NUM_MAX);
Serial.print("Current SMS number in memory is ");
Serial.println(smsNum2);
}

void loop()
{
char c;

// If there are any SMSs available()
if (sms.available())
{
Serial.println("Message received from:");

// Get remote number
sms.remoteNumber(senderNum, 20);
Serial.println(senderNum);

//save remote number if received in first 5 minutes after boot-up
if (millis() < (300000)){
strcpy(smsNum1, senderNum);
//write remote number to eeprom
eeprom_write_block(smsNum1, save, NUM_MAX);
//Confirm sms number change
Serial.print("SMS Number change accepted -");
eeprom_read_block(smsNum2, save, NUM_MAX);
Serial.println(smsNum2);
Serial.print("Sending Confirmation SMS");
sms.beginSMS(smsNum2);
sms.print("Your phone will receive SMS alerts for this device");
sms.endSMS();
}

//reject sms number change if after first 5 minutes of boot-up
else{
Serial.println("sms number change locked");
eeprom_read_block(smsNum2, save, NUM_MAX);
Serial.print("SMS Number is -");
Serial.println(smsNum2);
}

// Read message bytes and print them
while(c=sms.read())
Serial.print(c);

Serial.println("\nEND OF MESSAGE");

//Delete message from modem memory
sms.flush();
Serial.println("MESSAGE DELETED");

Serial.println("\nCOMPLETE!\n");
}

delay(1000);

}

TomyM:
This issue is now resolved. Here is the sketch that includes Jack's suggested modifications. Thanks again Jack!

You are welcome, glad to hear it works! Please in the future use code tags when posting code. Here's how:
http://forum.arduino.cc/index.php/topic,148850.msg1118324.html#post_codetags