Strings becoming null

I have a weird problem. I have an rfid program that checks for the rfid reader bits using software serial. In the main loop i also have a simple function that loops through a string and parse out values based on a delimiter. Inside this loop within this function, if I add an if statement or try Serial.print something else the orignal pageValue string I am evaluating become empty. I ran this program without the main loop and it functioned normally. I also discovered while troubleshooting that I was able to track down a seemingly random serial.println in the main loop that if i eliminated would allow the program to function normally as long as I did not change what was in the loop of the procedure afterword. Has anybody ever seen this. It seems like a memory allocation issue...I am surely stumped.

Bellow is sample of my loop with one the statements that causes problems commented out

String pageValue="Here; is some; sample;100;data;1.414;1020";
String line="a";
int leng = pageValue.length();
int delim= 0;
int loc=0;
int xx=0;
Card_Str="asdfasdfas";
while(delim!=-1){
delim=pageValue.indexOf(';',loc);
Serial.println(Card_Str);
//if (xx<10){
Serial.println(pageValue.substring(loc,delim));

//}

xx=xx+1;
loc=delim+1;
}//while

IMO classes such as String that use dynamic memory allocation have no place in an embedded platform with very limited memory such as the Arduino. The problem you are experiencing may well be caused by running out of RAM (assuming that the rest of the your program uses significant amounts of RAM), but it's hard to say for sure.

Hmm. I started with character array but had similar problems. Maybe I will go back to that to see if makes a difference. My program is 10180 of 30720 bytes so i would think it could handle a few strings. Let me try it with char array again and see if it still acts weird.

The size of your sketch has no relation to the amount of RAM you are using.
You need to post all your code.
(I second the comment about not using String)

My bad on the ram. I was not thinking. Returning to character arrays seems to be helping, but I want to go through it a couple more times to make sure the funny stuff does not happens when I add code. I do have two char arrays of size 20 for my rfid tags; that may be gobbling up the memory. I will post the code if/when this doesn't get fixed. Thanks everyone for the help so far. This really stumped me.

Two lots of 20 bytes will not gobble memory.
What will gobble memory is extreme fragmentation, but without seeing all your code, all we can do is guess what is going on.

A) USE CODE TAGS ( # button ) if you want to make friends here.
B) FIX YOUR POSTS

c) were you planning to use 'logical AND' ?

  if (queue[0] == 0 & queue[1] == 1 & queue[2] == 0 & queue[3] == 1 & queue[4] == 1) {
      sentinal = j - 4;
      break;
    }
  }

If so, use '&&' instead of '&' and read the manual regarding boolean operators.

My bad. I am new to posting. I will

#include <TextFinder.h>
#include <Client.h>
#include <Ethernet.h>
#include <SPI.h>
#include <SoftwareSerial.h>



#define rxPin 6
#define txPin 7

// Create a software serial object for the connection to the RFID module
SoftwareSerial rfid = SoftwareSerial( rxPin, txPin );


#define ledPin 13



// The tag database consists of two parts. The first part is an array of
// tag values with each tag taking up 5 bytes. The second is a list of
// names with one name for each tag (ie: group of 5 bytes).
char* allowedTags[] = {
  "1C00EFE643",         // Tag 1
  "04146E8BDD",         // Tag 2
  "0413BBBF23",         // Tag 3
   "1B001421DA",         // Tag 4
   "1B001461DA",         // Tag 5
   "1B001321DA",         // Tag 6
   "1B001221DA",         // Tag 7
   "1B002421Db",         // Tag 8
   "1B011421D1",         // Tag 9
   "1B101421D2",         // Tag 11
   "1B101421D2",         // Tag 12
   "1B101421D2",         // Tag 13
   "1B101421D2",         // Tag 14
   "1B101421D2",         // Tag 15
   "1B101421D2",         // Tag 16
   "1B101421D2",         // Tag 17
   "1B101421D2",         // Tag 18
   "1B101421D2",         // Tag 19
   "1B101421D2",         // Tag 20
};

// List of names to associate with the matching tag IDs
char* tagName[] = {
  "Jonathan Oxer",      // Tag 1
  "Hugh Blemings",      // Tag 2
  "Dexter D Dog",       // Tag 3
  "Set Paper Low",      // Tag 4
  "Jonathan Oxer",      // Tag 5
  "Hugh Blemings",      // Tag 6
  "Dexter D Dog",       // Tag 7
  "Paper Low8",          // Tag 8
  "Jonathan Oxer",      // Tag 9
  "Hugh Blemings",      // Tag 10
  "Dexter D Dog",       // Tag 11
  "Paper Low12",          // Tag 12
  "Paper Low13",          // Tag 13
  "Paper Low14",          // Tag 14
  "Paper Low15",          // Tag 15
  "Paper Low16",          // Tag 16
  "Paper Low17",          // Tag 17
  "Paper Low18",          // Tag 18
  "Paper Low19",          // Tag 19
  "Paper Low20",          // Tag 20
};

int cld1Pin = 4;            // Card status pin
int rdtPin = 2;             // Data pin
int reading = 0;            // Reading status
volatile int buffer[400];   // Buffer for data
volatile int i = 0;         // Buffer counter
volatile int bit = 0;       // global bit
char cardData[40];          // holds card info
int charCount = 0;          // counter for info
int DEBUG = 0;
unsigned int cnt=0;
String Card_Str="";

// Check the number of tags defined
int numberOfTags = sizeof(allowedTags)/sizeof(allowedTags[0]);
char* states[]={
  "checked out",
  "Checked In ",
  "Supplies Low ", 
  "Supplies High "
};
   


int incomingByte = 0;    // To store incoming serial data

///////////////////////////////////////////////////////////////////////
//CONFIGURE ethernet
////////////////////////////////////////////////////////////////////////
 /* byte ip[] = { 192, 168, 0, 199 };   //ip address to assign the arduino
  byte server[] = {174,123,231,247}; //ip Address of the server you will connect to

  //The location to go to on the server
  //make sure to keep HTTP/1.0 at the end, this is telling it what type of file it is
  //String location = "/~bildr/examples/ethernet/ HTTP/1.0";
 
  //Rarly need to change this
  byte subnet[] = { 255, 255, 255, 0 };

  // if need to change the MAC address (Very Rare)
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

  Client client(server, 80); // port 80 is typical www page*/

////////////////////////////////////////////////////////////////////////

char inString[32]; // string for incoming serial data
int stringPos = 0; // string index counter
boolean startRead = false; // is reading?

/**
 * Setup
 */
void setup() {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  pinMode(strikePlate, OUTPUT);
  digitalWrite(strikePlate, LOW);

  Serial.begin(9600);   // Serial port for connection to host
  rfid.begin(9600);      // Serial port for connection to RFID module
  
   // The interrupts are key to reliable
  // reading of the clock and data feed
  attachInterrupt(0, changeBit, CHANGE);
  attachInterrupt(1, writeBit, FALLING);

  Serial.println("RFID reader starting up");
}

/**
 * Loop
 */

/**
 * Loop
 */
void loop() {
  byte i         = 0;
  byte val       = 0;
  byte checksum  = 0;
  byte bytesRead = 0;
  byte tempByte  = 0;
  byte tagBytes[6];    // "Unique" tags are only 5 bytes but we need an extra byte for the checksum
  char tagValue[10];
  int state=0;
  
    get_supplies(1);  //this is where the problem is
 
  
  // Read from the RFID module. Because this connection uses SoftwareSerial
  // there is no equivalent to the Serial.available() function, so at this
  // point the program blocks while waiting for a value from the module
  if((val = rfid.read()) == 2) {        // Check for header
    bytesRead = 0;
    while (bytesRead < 12) {            // Read 10 digit code + 2 digit checksum
      val = rfid.read();

      // Append the first 10 bytes (0 to 9) to the raw tag value
      if (bytesRead < 10)
      {
        tagValue[bytesRead] = val;
      }

      // Check if this is a header or stop byte before the 10 digit reading is complete
      if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) {
        break;                          // Stop reading
      }

      // Ascii/Hex conversion:
      if ((val >= '0') && (val <= '9')) {
        val = val - '0';
      }
      else if ((val >= 'A') && (val <= 'F')) {
        val = 10 + val - 'A';
      }

      // Every two hex-digits, add a byte to the code:
      if (bytesRead & 1 == 1) {
        // Make space for this hex-digit by shifting the previous digit 4 bits to the left
        tagBytes[bytesRead >> 1] = (val | (tempByte << 4));

        if (bytesRead >> 1 != 5) {                // If we're at the checksum byte,
          checksum ^= tagBytes[bytesRead >> 1];   // Calculate the checksum... (XOR)
        };
      } else {
        tempByte = val;                           // Store the first hex digit first
      };

      bytesRead++;                                // Ready to read next digit
    }

    // Send the result to the host connected via USB
    if (bytesRead == 12) {                        // 12 digit read is complete
      tagValue[10] = '\0';                        // Null-terminate the string

      Serial.print("Tag read: ");
      for (i=0; i<5; i++) {
        // Add a leading 0 to pad out values below 16
        if (tagBytes[i] < 16) {
          Serial.print("0");
        }
        Serial.print(tagBytes[i], HEX);
      }
      Serial.println();

      Serial.print("Checksum: ");
      Serial.print(tagBytes[5], HEX);
      Serial.println(tagBytes[5] == checksum ? " -- passed." : " -- error.");

      // Show the raw tag value
      //Serial.print("VALUE: ");
      //Serial.println(tagValue);

      // Search the tag database for this particular tag
      int tagId = findTag( tagValue );

      // if tag is found
      if( tagId > 0 )
       Serial.print("Authorized tag ID ");
        Serial.println(tagId);
        if(tagId<30){//equipment
            Serial.print("State:");
           Serial.println(state);
            Serial.println(states[state]);
            switch (state) {
              case 0: //checked out
              Serial.print(tagName[tagId - 1]);
             // Serial.println("Checked out, Scan ID to Check in");
              if(Scan_ID()==1){//id scan ok
                 if(senddata(tagId,2)==1){
                   Serial.print("Updated Record");
                 }
                 else{
                   Serial.print("Could not access server");
                 }
              }
              else{
                //Serial.println("ID Not valid or could not be read");
              }
              break;
            case 1://checked in check out
              Serial.print(tagName[tagId - 1]);
              Serial.println(" Checked in, Scan ID to Check Out");
              if(Scan_ID()==1){//id scan ok
                 if(senddata(tagId,1)==1){
               //    Serial.print("Updated Record");
                 }
                 else{
                   Serial.print("Could not access server");
                 }
              }
              else{
                Serial.println("ID Not valid or could not be read");
              }
              break;
              
            }//switch
        }//equip if
        else{  // supplies
        }
      {
        
      }// tag if
      Serial.println();     // Blank separator line in output
    }

    bytesRead = 0;
  }
  
 
}
int check_status(int tag) {//get tags status

   //String location = "/http://www.underthemountain.org/";
  String location = String("/inventory/status.php?tag="+ String(tag) + " HTTP/1.0");
  String pageValue = connectAndRead(location);
  digitalWrite(ledPin, HIGH);
  delay(500);
  return atoi("3");
  digitalWrite(ledPin, LOW);
}
/**
 * Get user status from the DB
 */
int CheckUser(){

   return 1;
}


/**
 * Search for a specific tag in the database
 */
int findTag( char tagValue[10] ) {
  for (int thisCard = 0; thisCard < numberOfTags; thisCard++) {
    // Check if the tag value matches this row in the tag database
    if(strcmp(tagValue, allowedTags[thisCard]) == 0)
    {
      // The row in the database starts at 0, so add 1 to the result so
      // that the card ID starts from 1 instead (0 represents "no match")
      return(thisCard + 1);
    }
  }
  // If we don't find the tag return a tag ID of 0 to show there was no match
  return(0);
}


int Scan_ID(){
  Card_Str="";
  unsigned int exit=0;
  unsigned int timeout = millis();
  unsigned int track=0;
  while(((millis()-timeout)< 10000) && exit==0){ // set this to your timeout value in milliseconds
    // Active when card present
    //Serial.println(millis()-timeout);
    while(digitalRead(cld1Pin) == LOW){
      reading = 1;
    }     
   
    // Active when read is complete
    // Reset the buffer
    if(reading == 1) {  
   
      if (DEBUG == 1) {
        printBuffer(track);
      }
      decode(track);
      track++;
      reading = 0;
      if (Card_Str[0]=='9' && Card_Str.length()>8){
        Serial.println("valid:");
        if(CheckUser()==1){
          return 1;
        }
        else{
          return 0;
        }
        exit=1;
      }
      i = 0;
   
      int l;
      for (l = 0; l < 40; l = l + 1) {
        cardData[l] = '\n';
      }
   
      charCount = 0;
    }
  }
  timeout = 0;
  int first9 = Card_Str.indexOf('>');
 
}



unsigned int senddata(int tag,int state)
{

  
   //The location to go to on the server
   //make sure to keep HTTP/1.0 at the end, this is telling it what type of file it is
   //Ethernet.begin(mac, ip);
   //GET http://server.com/script.php?tag="
   //String location = "/http://www.underthemountain.org/";
  String location =String("/inventory/update.php?tag="+ String(tag) + "&state="+ String(state)+ "&id="+ String(Card_Str) + " HTTP/1.0");
  String pageValue = connectAndRead(location);
   digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  
  char carray[pageValue.length()];
  pageValue.toCharArray(carray, sizeof(carray));
  return atoi(carray);
  
}

void get_supplies(int pge){
char sz[] = "3500,270,890,70,4";

 String location =String("/inventory/update.php?page="+String(pge));
 String pageValue = connectAndRead(location);
 
 char carray[pageValue.length()];
 pageValue.toCharArray(carray, sizeof(carray));

 int x=0;
 char *p = carray;
 char *str;

while (str = strtok_r(p, ",", &p)){ // delimiter is the semicolon
   if(x==3){
     Serial.println(str);
     x=0;
   }
   Serial.print(str);
   Serial.print("  |  ");
 }

}



// Flips the global bit
void changeBit(){
  if (bit == 0) {
    bit = 1;
  } else {
    bit = 0;
  }
}
 
// Writes the bit to the buffer
void writeBit(){
  buffer[i] = bit;
  i++;
}
 
// prints the buffer
void printBuffer(unsigned int trk ){
  int j;
  for (j = 0; j < 200; j = j + 1) {
    Serial.println(buffer[j]);
  }
}
 
int getStartSentinal(){
  int j;
  int queue[5];
  int sentinal = 0;
 
  for (j = 0; j < 400; j = j + 1) {
    queue[4] = queue[3];
    queue[3] = queue[2];
    queue[2] = queue[1];
    queue[1] = queue[0];
    queue[0] = buffer[j];
 
    if (DEBUG == 1) {
      Serial.print(queue[0]);
      Serial.print(queue[1]);
      Serial.print(queue[2]);
      Serial.print(queue[3]);
      Serial.println(queue[4]);
    }
 
    if (queue[0] == 0 & queue[1] == 1 & queue[2] == 0 & queue[3] == 1 & queue[4] == 1) {
      sentinal = j - 4;
      break;
    }
  }
 
  if (DEBUG == 1) {
    Serial.print("sentinal:");
    Serial.println(sentinal);
    Serial.println("");
  }
 
  return sentinal;
}
 
void decode(unsigned int trk) {
  int sentinal = getStartSentinal();
  int j;
  int i = 0;
  int k = 0;
  int thisByte[5];
 
  for (j = sentinal; j < 400 - sentinal; j = j + 1) {
    thisByte[i] = buffer[j];
    i++;
    if (i % 5 == 0) {
      i = 0;
      if (thisByte[0] == 0 & thisByte[1] == 0 & thisByte[2] == 0 & thisByte[3] == 0 & thisByte[4] == 0) {
        break;
      }
      printMyByte(thisByte);
    }
  }
 Serial.print("Track:");
 Serial.println(trk);
 //if(trk==0){
    Serial.print("Stripe_Data:");
    String Cardstr="";
    for (k = 0; k < charCount; k = k + 1) {
      Serial.print(cardData[k]);
      Cardstr+=cardData[k];
      //Serial.print(Cardstr);
    }
   // if(trk==0){
       Card_Str=Cardstr;
  //  }
    Serial.println("");
// }
 
}
 
void printMyByte(int thisByte[]) {
  int i;
  for (i = 0; i < 5; i = i + 1) {
    if (DEBUG == 1) {
      Serial.print(thisByte[i]);
    }
}
    if (DEBUG == 1) {
      Serial.print("\t");
      Serial.print(decodeByte(thisByte));
      Serial.println("");
    }
 
    cardData[charCount] = decodeByte(thisByte);
    charCount ++;
}
 
char decodeByte(int thisByte[]) {
    if (thisByte[0] == 0 & thisByte[1] == 0 & thisByte[2] == 0 & thisByte[3] == 0 & thisByte[4] == 1){
      return '0';
    }
    if (thisByte[0] == 1 & thisByte[1] == 0 & thisByte[2] == 0 & thisByte[3] == 0 & thisByte[4] == 0){
      return '1';
    }
 
    if (thisByte[0] == 0 & thisByte[1] == 1 & thisByte[2] == 0 & thisByte[3] == 0 & thisByte[4] == 0){
      return '2';
    }
 
    if (thisByte[0] == 1 & thisByte[1] == 1 & thisByte[2] == 0 & thisByte[3] == 0 & thisByte[4] == 1){
      return '3';
    }
 
    if (thisByte[0] == 0 & thisByte[1] == 0 & thisByte[2] == 1 & thisByte[3] == 0 & thisByte[4] == 0){
      return '4';
    }
 
    if (thisByte[0] == 1 & thisByte[1] == 0 & thisByte[2] == 1 & thisByte[3] == 0 & thisByte[4] == 1){
      return '5';
    }
 
    if (thisByte[0] == 0 & thisByte[1] == 1 & thisByte[2] == 1 & thisByte[3] == 0 & thisByte[4] == 1){
      return '6';
    }
 
    if (thisByte[0] == 1 & thisByte[1] == 1 & thisByte[2] == 1 & thisByte[3] == 0 & thisByte[4] == 0){
      return '7';
    }
 
    if (thisByte[0] == 0 & thisByte[1] == 0 & thisByte[2] == 0 & thisByte[3] == 1 & thisByte[4] == 0){
      return '8';
    }
 
    if (thisByte[0] == 1 & thisByte[1] == 0 & thisByte[2] == 0 & thisByte[3] == 1 & thisByte[4] == 1){
      return '9';
    }
 
    if (thisByte[0] == 0 & thisByte[1] == 1 & thisByte[2] == 0 & thisByte[3] == 1 & thisByte[4] == 1){
      //return ':';
    }
 
    if (thisByte[0] == 1 & thisByte[1] == 1 & thisByte[2] == 0 & thisByte[3] == 1 & thisByte[4] == 0){
      //return ';';
    }
 
    if (thisByte[0] == 0 & thisByte[1] == 0 & thisByte[2] == 1 & thisByte[3] == 1 & thisByte[4] == 1){
      //return '<';
    }
 
    if (thisByte[0] == 1 & thisByte[1] == 0 & thisByte[2] == 1 & thisByte[3] == 1 & thisByte[4] == 0){
      //return '=';
    }
 
    if (thisByte[0] == 0 & thisByte[1] == 1 & thisByte[2] == 1 & thisByte[3] == 1 & thisByte[4] == 0){
      //return '>';
    }
 
    if (thisByte[0] == 1 & thisByte[1] == 1 & thisByte[2] == 1 & thisByte[3] == 1 & thisByte[4] == 1){
      //return '?';
    }
}

String connectAndRead(String loc){
  
  
 //connect to the server
/*
  Serial.println("connecting...");

  if (client.connect()) {
    Serial.println("connected");
    client.print("GET ");
    client.println(loc);
    client.println();

    //Connected - Read the page
    return readPage(); //go and read the output

  }else{
    return "connection failed";
  }*/
  return "Tom,Jones, 54,54,Sept 12,Jim, Bo 56,56,Sept,43";
}

String readPage(){
//read the page, and capture & return everything between '<' and '>'

/*  stringPos = 0;
  memset( &inString, 0, 32 ); //clear inString memory

  while(true){

    if (client.available()) {
      char c = client.read();

      if (c == '<' ) { //'<' is our begining character
        startRead = true; //Ready to start reading the part 
      }else if(startRead){

        if(c != '>'){ //'>' is our ending character
          inString[stringPos] = c;
          stringPos ++;
        }else{
          //got what we need here! We can disconnect now
          startRead = false;
          client.stop();
          client.flush();
          Serial.println("disconnecting.");
          return inString;

        }

      }
    }

  }*/

}

Thanks mad worm. I made those changes, but the problem still persists. I think I might try to change ethernet calls to return char arrays to see if that helps.

Seems to be working better after I got rid of some stings and fixed the logical ands in the example code i used.

You have a lot of string literals, which are using RAM. I suggest you move some of them to flash. See reply #1 of thread http://arduino.cc/forum/index.php/topic,72244.0.html for how I do it.