Arduino Loading doesn't work Hello I have an Arduino program that loads strings from a file and stores them in an array. It works fine when I load it the first time but when I load it a second time it doesn't seem to work.

 String content = "";

 char character23;

 String result[10];
 int arraysize = 10;

 void loadPrograme(String sss){
   File file = SD.open("basic.txt", FILE_READ);
   Serial.print("Reading, Checking and Compiling \n\n\n");  

   for (int i = 0; i &lt; arraysize; i++) { 
     result[i] = "";
   }

   for (int i = 0; i &lt; arraysize; i++) {
     while (file.available()) {
       character23 = file.read(); 
       if (character23 == '\n') break; 
       if (character23 != '^') { 
         content += character23; 
       } 
     } 
     content.trim(); 
     if (content != "") { 
       result[i] = content; 
       content = "";
     } 
   } 

   for (int i = 0; i &lt;arraysize; i++) { 
     Serial.print("result["); 
     Serial.print(i); 
     Serial.print("]: "); 
     Serial.println(result[i]); 
   }
   file.close();
 }


This works fine when I call loadProgramme("basic.txt") in the setup function.

void loadfileMethod(String s){
  if(consolemode){
    u8g.setFont(u8g_font_micro);
    u8g.drawStr(2, 6-camy, s.c_str());
    camy+=6;
  }
  camy = 0;
  loadPrograme("names.txt");
}   


When I call loadprograme in this method it runs through loadrograme but only gets as far as the while loop and it doesn't do anything in the while loop.(I check this using serial.println(). 

Can someone tell me what I'm doing wrong that makes it work the first time and not the second?

EDIT: I found the problem but I don't know how to fix it. when I do Serial.println(file.name()); it prints the correct name the first time but the second time it just prints a tiny box which I presume is nothing or an error. 

How can I fix this?
If you know that your while loop isn't working as expected, I'd instrument the while loop and see if it parses as you expect:

for (int i = 0; i &lt; arraysize; i++) {
  while (file.available()) {
    character23 = file.read(); 
    if (character23 == '\n') break; 
    if (character23 != '^') { 
      content += character23; 
    }
    Serial.print(i);
    Serial.print(':');
    Serial.print(character23);
    Serial.print(':');
    Serial.println(content); 
  } 
  content.trim(); 
  if (content != "") { 
    result[i] = content; 
    content = "";
  } 
} 


Are you certain it is working the first time?