Why my table have this chars?

When i put my table on Serial monitor, this is what my table show:

This is part of my code:

#include <LiquidCrystal.h>
#include <SPI.h>
#include <SD.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// define some values used by the panel and buttons
int lcd_key     = 0;
//char *tab, *tab1;
int adc_key_in  = 0;
int x = 0;
String files, memo, memo1;
int sizef = 0;
int cont = 0; 
int y=0;
int sizef1 = 0;
int sizef2 = 0;
//char floatbuf[32]
//char copy [50];
//objeto_celeste.toCharArray(floatbuf, sizeof(floatbuf));
//float f = atof(floatbuf);

struct objeto_celeste_s {
  char nome[12];
  float ar;
  float dec; 
  };
typedef struct objeto_celeste_s objeto_celeste; 

//objeto_celeste *tab;

File root;
File file;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

char * list[]={"1.Modo Normal    ", "2.Modo Teste    ","                "};

// read the buttons
int read_LCD_buttons()
{
 
adc_key_in = analogRead(0);
if (adc_key_in > 1000) return btnNONE;
if (adc_key_in < 50)   return btnRIGHT;  
if (adc_key_in < 250)  return btnUP; 
if (adc_key_in < 400)  return btnDOWN; 
if (adc_key_in < 450)  return btnLEFT;
if (adc_key_in < 650)  return btnSELECT;   

return btnNONE;  // when all others fail, return this...
}

void setup() {

 Serial.begin(9600);
 while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
 } 
 Serial.println ("Welcome!");
 Serial.println ("Selecione um modo no lcd.");
 lcd.begin (16,2);
 lcd.setCursor (0,0);
 lcd.print ("  Selecione um");
 lcd.setCursor (0,1);
 lcd.print ("      modo    ");
 delay (3000);
 drawList (0,1);
 

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }

 root = SD.open("/");
 printDirectory(root, 0);
}
 void printDirectory(File dir, int numTabs) {
  while (true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    entry.close();
 }
}

void drawList(int line1, int line2){
  lcd.clear ();
    lcd.setCursor(0,0);
    if(line1 == x){
      lcd.print(">");
    }
    lcd.println(list[line1]);

    lcd.setCursor(0,1);
    lcd.print (" ");
    lcd.println(list[line2]);

}


void loop() {


  
lcd_key = read_LCD_buttons();  // read the buttons

 switch (lcd_key)  // depending on which button was pushed, we perform an action
 {
   case btnRIGHT:   
     break;

   case btnLEFT:
     break;

   case btnUP:
      if(x==1){
        x--;
        drawList(x,x+1);
      }
      break;
   
   case btnDOWN:
      if(x==0){
        x++;
        drawList(x,x+1);
      }
     break;
     

   case btnSELECT:
    lcd.clear ();
    if (x==0){
    lcd.clear ();  
    lcd.print ("Modo Normal");
    Serial.println ("Selecionou o modo normal!");
    delay (2000);
    if (SD.exists("objectos.txt")) {
    Serial.println("O ficheiro 'objetos' foi encontrado!");
    lcd.clear ();
    lcd.setCursor (0,0);
    lcd.print ("Modo Normal");
    delay (2000);
    file = SD.open("objectos.txt", FILE_READ);
    if (file) {
    while (file.available()) {
     String line = file.readStringUntil('\n');
     sizef++;
    }
    } else {//se houver erro a abrir o ficheiro 
     Serial.println("Erro a abrir o ficheiro 'objectos.txt'.");
    }
     //objeto_celeste tab[sizef]; 
    objeto_celeste *tab =(objeto_celeste *)malloc((sizef) * sizeof(objeto_celeste));
     files = "Contados " + String (sizef) + " objetos no ficheiro objetos.txt.";
     Serial.println (files);
     memo = "Alocados " + String (sizef) + " obj  ";
     memo1= "Memória alocada para " + String (sizef) + " objetos.";
     if (tab==NULL){
      lcd.clear ();
      lcd.print ("Erro a alocar memoria");
      Serial.println ("Erro a alocar memória");
      while (1){ }; 
     }else{
      Serial.println (memo1);
      lcd.setCursor (0,1);
      lcd.print (memo);
      }
      file.close();
    
    file = SD.open("objectos.txt", FILE_READ);
    if (file) {
    while (file.available()) {
     if ((file.read())=='\n'){
     char * justfun = strtok (sizef, " ");
     while (justfun !=NULL){ 
      switch (sizef1){
        case 0:
         strcpy ( tab[sizef2].nome, justfun);
         sizef1 ++;
        break;

        case 1:
         tab[sizef2].ar = atof (justfun);
         sizef1++;
        break;

        case 2:
         tab[sizef2].dec = atof (justfun);
         sizef1=0;
         sizef2++;
         break;
      }
      justfun = strtok (NULL, " ");
     }
     }
    }
   }
   file.close ();
   for (int i=0 ; i<sizef ; i++){
    Serial.print(tab[i].nome);
    Serial.print (' ');
    Serial.print (tab[i].ar);
    Serial.print (' ');
    Serial.print (tab[i].dec);
    Serial.print('\n') ;
   }
  }else {
    Serial.println ("O ficheiro 'objetos' não existe.");
    lcd.clear ();
    lcd.print ("Erro nao encontrado");
    delay (2000);
    while(1) { };
  }
 }

Hi and welcome to the forum.
Congrats on using code tags on your first post! Karma++

Your image is hard to read. Can you paste the results into the post? You can use the code tags for that too.

vinceherman:
Hi and welcome to the forum.
Congrats on using code tags on your first post! Karma++

Your image is hard to read. Can you paste the results into the post? You can use the code tags for that too.

Hi, thank you!

There is the image:

Looks like you are not calling strtok() correctly. I think this:

char * justfun = strtok (sizef, " ");

is supposed to be this:

char * justfun = strtok (tab, " ");

Hi, thank you for your reply, i already have done that and don't work...

If i do that, show this issue:

Did you try casting tab?

char * justfun = strtok ((char *)tab, " ");

If your code has changed you should post the new version.

We have seen you can use code tags, now you are not using them.

BTW, according to your 'name' you know something.

Thank you again… Well the problem of table is the same…

Look:

http://prntscr.com/is79fm

P.S. I didn’t change anything on code…

larryd:
We have seen you can use code tags, now you are not using them.

BTW, according to your 'name' you know something.

Heheh, i don't know nothing about programming, that's why my nickname... I'm a noobie.

idontknownothing:
Heheh, i don't know nothing about

. . . Augustus de Morgan

Heheh, i don't know nothing about programming, that's why my nickname... I'm a noobie.

Double negative equals positive. :wink:

Anyone knows what's the problem?

Not solved....

Split your code up into logical sections to troubleshoot it.

Enable/disable sections as needed to isolate your problem.

Always show us your ‘current’ compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]

larryd:
Split your code up into logical sections to troubleshoot it.

Enable/disable sections as needed to isolate your problem.

Always show us your ‘current’ compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]

There’s my full code, can anyone help me?

#include <LiquidCrystal.h>
#include <SPI.h>
#include <SD.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// define some values used by the panel and buttons
int lcd_key     = 0;
//char *tab, *tab1;
int adc_key_in  = 0;
int x = 0;
String files, memo, memo1;
int sizef = 0;
int cont = 0; 
int y=0;
int sizef1 = 0;
int sizef2 = 0;
//char floatbuf[32]
//char copy [50];
//objeto_celeste.toCharArray(floatbuf, sizeof(floatbuf));
//float f = atof(floatbuf);

struct objeto_celeste_s {
  char nome[12];
  float ar;
  float dec; 
  };
typedef struct objeto_celeste_s objeto_celeste; 

//objeto_celeste *tab;

File root;
File file;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

char * list[]={"1.Modo Normal    ", "2.Modo Teste    ","                "};

// read the buttons
int read_LCD_buttons()
{
 
adc_key_in = analogRead(0);
if (adc_key_in > 1000) return btnNONE;
if (adc_key_in < 50)   return btnRIGHT;  
if (adc_key_in < 250)  return btnUP; 
if (adc_key_in < 400)  return btnDOWN; 
if (adc_key_in < 450)  return btnLEFT;
if (adc_key_in < 650)  return btnSELECT;   

return btnNONE;  // when all others fail, return this...
}

void setup() {

 Serial.begin(9600);
 while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
 } 
 Serial.println ("Welcome!");
 Serial.println ("Selecione um modo no lcd.");
 lcd.begin (16,2);
 lcd.setCursor (0,0);
 lcd.print ("  Selecione um");
 lcd.setCursor (0,1);
 lcd.print ("      modo    ");
 delay (3000);
 drawList (0,1);
 

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }

 root = SD.open("/");
 printDirectory(root, 0);
}
 void printDirectory(File dir, int numTabs) {
  while (true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    entry.close();
 }
}

void drawList(int line1, int line2){
  lcd.clear ();
    lcd.setCursor(0,0);
    if(line1 == x){
      lcd.print(">");
    }
    lcd.println(list[line1]);

    lcd.setCursor(0,1);
    lcd.print (" ");
    lcd.println(list[line2]);

}


void loop() {


  
lcd_key = read_LCD_buttons();  // read the buttons

 switch (lcd_key)  // depending on which button was pushed, we perform an action
 {
   case btnRIGHT:   
     break;

   case btnLEFT:
     break;

   case btnUP:
      if(x==1){
        x--;
        drawList(x,x+1);
      }
      break;
   
   case btnDOWN:
      if(x==0){
        x++;
        drawList(x,x+1);
      }
     break;
     

   case btnSELECT:
    lcd.clear ();
    if (x==0){
    lcd.clear ();  
    lcd.print ("Modo Normal");
    Serial.println ("Selecionou o modo normal!");
    delay (2000);
    if (SD.exists("objectos.txt")) {
    Serial.println("O ficheiro 'objetos' foi encontrado!");
    lcd.clear ();
    lcd.setCursor (0,0);
    lcd.print ("Modo Normal");
    delay (2000);
    file = SD.open("objectos.txt", FILE_READ);
    if (file) {
    while (file.available()) {
     String line = file.readStringUntil('\n');
     sizef++;
    }
    } else {//se houver erro a abrir o ficheiro 
     Serial.println("Erro a abrir o ficheiro 'objectos.txt'.");
    }
     //objeto_celeste tab[sizef]; 
    objeto_celeste *tab =(objeto_celeste *)malloc((sizef) * sizeof(objeto_celeste));
     files = "Contados " + String (sizef) + " objetos no ficheiro objetos.txt.";
     Serial.println (files);
     memo = "Alocados " + String (sizef) + " obj  ";
     memo1= "Memória alocada para " + String (sizef) + " objetos.";
     if (tab==NULL){
      lcd.clear ();
      lcd.print ("Erro a alocar memoria");
      Serial.println ("Erro a alocar memória");
      while (1){ }; 
     }else{
      Serial.println (memo1);
      lcd.setCursor (0,1);
      lcd.print (memo);
      }
      file.close();
    
    file = SD.open("objectos.txt", FILE_READ);
    if (file) {
    while (file.available()) {
     if ((file.read())=='\n'){
     char * justfun = strtok ((char*)tab, " ");
     while (justfun !=NULL){ 
      switch (sizef1){
        case 0:
         strcpy ( tab[sizef2].nome, justfun);
         sizef1 ++;
        break;

        case 1:
         tab[sizef2].ar = atof (justfun);
         sizef1++;
        break;

        case 2:
         tab[sizef2].dec = atof (justfun);
         sizef1=0;
         sizef2++;
         break;
      }
      justfun = strtok (NULL, " ");
     }
     }
    }
   }
   file.close ();
   for (int i=0 ; i<sizef ; i++){
    Serial.print(tab[i].nome);
    Serial.print (' ');
    Serial.print (tab[i].ar);
    Serial.print (' ');
    Serial.print (tab[i].dec);
    Serial.print('\n') ;
   }
  }else {
    Serial.println ("O ficheiro 'objetos' não existe.");
    lcd.clear ();
    lcd.print ("Erro nao encontrado");
    delay (2000);
    while(1) { };
  }
 }
    if (x==1){
      lcd.clear ();
      lcd.print ("Modo Teste");
      Serial.println ("Selecionou o modo teste!");
      delay (2000);
      if (SD.exists("teste.txt")) {
      Serial.println("O ficheiro 'teste.txt' foi encontrado!");
      lcd.clear ();
      lcd.setCursor (0,0);
      lcd.print ("Modo Teste");
      lcd.setCursor (0,1);
      lcd.print ("Ficheiro encontrado");
      delay (2000);
      file = SD.open("teste.txt", FILE_READ);
      if (file) {
      while (file.available()) {//ler o ficheiro
      String line = file.readStringUntil('\n');
      sizef++;
     }
      files = "Contados " + String (sizef) + " objetos no ficheiro teste.txt.";
      Serial.println (files);
      objeto_celeste *tab = malloc(sizef * sizeof(objeto_celeste));
      memo = "Alocados " + String (sizef) + " obj  ";
      memo1= "Memória alocada para " + String (sizef) + " objetos.";
      if (tab==NULL){
        lcd.clear ();
        lcd.print ("Erro alocar memoria");
        Serial.println ("Erro a alocar memória");
        while (1){ };
      }else{
        Serial.println (memo1);
        lcd.setCursor (0,1);
        lcd.print (memo);
      }
      file.close();
     } else {//se houver erro a abrir o ficheiro 
      Serial.println("Erro a abrir o ficheiro 'teste.txt'.");
     }
    }else {
      Serial.println ("O ficheiro 'teste.txt' não foi encontrado.");
      lcd.clear ();
      lcd.print ("Erro nao encontrado");
      delay (2000);
      while(1) { };
    }
   }
     break;
   
   case btnNONE:
      break;
 }    
 delay (200);
}

And another question, how can i do this without cases?

And another question, how can i do this without cases?

How can you do WHAT without cases? Why would you want to?

When are you going to post the TEXT in the serial monitor app AS TEXT, so we can see it? I am NOT going to some virus-infected site to download a picture of f*king text.

PaulS:
How can you do WHAT without cases? Why would you want to?

When are you going to post the TEXT in the serial monitor app AS TEXT, so we can see it? I am NOT going to some virus-infected site to download a picture of f*king text.

Hi, there’s a image!

This is my code:

#include <LiquidCrystal.h>
#include <SPI.h>
#include <SD.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
int x = 0;
String files, memo, memo1;
int sizef = 0;
int cont = 0; 
int y=0;
int sizef1 = 0;
int sizef2 = 0;

struct objeto_celeste_s {
  char nome[20];
  float ar;
  float dec; 
  };
typedef struct objeto_celeste_s objeto_celeste; 

//objeto_celeste *tab;

File root;
File file;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

char * list[]={"1.Modo Normal    ","2.Modo Teste    "};

// read the buttons
int read_LCD_buttons()
{
 
adc_key_in = analogRead(0);
if (adc_key_in > 1000) return btnNONE;
if (adc_key_in < 50)   return btnRIGHT;  
if (adc_key_in < 250)  return btnUP; 
if (adc_key_in < 400)  return btnDOWN; 
if (adc_key_in < 450)  return btnLEFT;
if (adc_key_in < 650)  return btnSELECT;   

return btnNONE;  // when all others fail, return this...
}

void setup() {

 Serial.begin(9600);
 while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
 } 
 Serial.println ("Welcome!");
 Serial.println ("Selecione um modo no lcd.");
 lcd.begin (16,2);
 lcd.setCursor (0,0);
 lcd.print ("  Selecione um");
 lcd.setCursor (0,1);
 lcd.print ("      modo    ");
 delay (3000);
 lcd.clear ();
 lcd.setCursor(0,0);
 lcd.print(">");
 lcd.println(list[0]);
 lcd.setCursor(0,1);
 lcd.print (" ");
 lcd.println(list[1]);
 

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }

 root = SD.open("/");
 printDirectory(root, 0);
}
 void printDirectory(File dir, int numTabs) {
  while (true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    entry.close();
 }
}


void loop() {
  
lcd_key = read_LCD_buttons();  // read the buttons

 switch (lcd_key)  // depending on which button was pushed, we perform an action
 {
   case btnRIGHT:   
     break;

   case btnLEFT:
     break;

   case btnUP:
      if(x==1){
        x--;
        lcd.clear ();
        lcd.setCursor(0,0);
        lcd.print(">");
        lcd.println(list[0]);
        lcd.setCursor(0,1);
        lcd.print (" ");
        lcd.println(list[1]);
      }
      break;
   
   case btnDOWN:
      if(x==0){
        x++;
        lcd.clear ();
        lcd.setCursor(0,0);
        lcd.print(">");
        lcd.println(list[1]);
        lcd.setCursor(0,1);
        lcd.println("                ");
      }
     break;
     

   case btnSELECT:
    lcd.clear ();
    if (x==0){
    lcd.clear ();  
    lcd.print ("Modo Normal");
    Serial.println ("Selecionou o modo normal!");
    delay (2000);
    if (SD.exists("objectos.txt")) {
    Serial.println("O ficheiro 'objetos' foi encontrado!");
    lcd.clear ();
    lcd.setCursor (0,0);
    lcd.print ("Modo Normal");
    delay (2000);
    file = SD.open("objectos.txt", FILE_READ);
    if (file) {
    while (file.available()) {
     String line = file.readStringUntil('\n');
     String line1 = line;
     sizef++;
    }
    } else {//se houver erro a abrir o ficheiro 
     Serial.println("Erro a abrir o ficheiro 'objectos.txt'.");
    }
     //objeto_celeste tab[sizef]; 
    
     objeto_celeste *tab =(objeto_celeste *)malloc((sizef) * sizeof(objeto_celeste));
     files = "Contados " + String (sizef) + " objetos no ficheiro objetos.txt.";
     Serial.println (files);
     memo = "Alocados " + String (sizef) + " obj  ";
     memo1= "Memória alocada para " + String (sizef) + " objetos.";
     if (tab==NULL){
      lcd.clear ();
      lcd.print ("Erro a alocar memoria");
      Serial.println ("Erro a alocar memória");
      while (1){ }; 
     }else{
      Serial.println (memo1);
      lcd.setCursor (0,1);
      lcd.print (memo);
      }
      file.close();  
      
    file = SD.open("objetos.txt", FILE_READ);
    if (file) {
    while (file.available()) {
     if (file.read()=='\n'){ 
     char * justafun = strtok ((char *)tab, " ");//divide em tokens
     while (justafun !=NULL){
       while (sizef2<sizef){  
       strcpy ( tab[sizef2].nome, justafun);
       tab[sizef2].ar =atof (justafun);
       tab[sizef2].dec =atof (justafun);
       sizef2++;
       }
      justafun = strtok (NULL, " ");  
      }
     }
    }
   }
   for (int i=0 ; i<sizef ; i++){
    Serial.print(tab[i].nome);
    Serial.print (' ');
    Serial.print (tab[i].ar);
    Serial.print (' ');
    Serial.print (tab[i].dec);
    Serial.print('\n') ;
    file.close ();
   }
  }else {
    Serial.println ("O ficheiro 'objetos' não existe.");
    lcd.clear ();
    lcd.print ("Erro nao encontrado");
    delay (2000);
    while(1) { };
  }
 }
    if (x==1){
      lcd.clear ();
      lcd.print ("Modo Teste");
      Serial.println ("Selecionou o modo teste!");
      delay (2000);
      if (SD.exists("teste.txt")) {
      Serial.println("O ficheiro 'teste.txt' foi encontrado!");
      lcd.clear ();
      lcd.setCursor (0,0);
      lcd.print ("Modo Teste");
      lcd.setCursor (0,1);
      lcd.print ("Ficheiro encontrado");
      delay (2000);
      file = SD.open("teste.txt", FILE_READ);
      if (file) {
      while (file.available()) {//ler o ficheiro
      String line = file.readStringUntil('\n');
      sizef++;
     }
      files = "Contados " + String (sizef) + " objetos no ficheiro teste.txt.";
      Serial.println (files);
      objeto_celeste *tab = malloc(sizef * sizeof(objeto_celeste));
      memo = "Alocados " + String (sizef) + " obj  ";
      memo1= "Memória alocada para " + String (sizef) + " objetos.";
      if (tab==NULL){
        lcd.clear ();
        lcd.print ("Erro alocar memoria");
        Serial.println ("Erro a alocar memória");
        while (1){ };
      }else{
        Serial.println (memo1);
        lcd.setCursor (0,1);
        lcd.print (memo);
      }
      file.close();
     } else {//se houver erro a abrir o ficheiro 
      Serial.println("Erro a abrir o ficheiro 'teste.txt'.");
     }
    }else {
      Serial.println ("O ficheiro 'teste.txt' não foi encontrado.");
      lcd.clear ();
      lcd.print ("Erro nao encontrado");
      delay (2000);
      while(1) { };
    }
   }
     break;
   
   case btnNONE:
      break;
 }    
 delay (200);
}

And this is what i want to put on tab:

Syrius 6h45m8.9s -16°42'52.1" 
Deneb 20h41m25.9s +45°16'49.2" 
Capella 5h16m41.4s +45°59'52.4" 
Rigel 5h14m32.3s -8°12'05.9" 
Vega 18h36m56.3s +38°47'01.9" 
Alnitak 05h40m45.5s -01°56'34"

But, instead what print in serial monitor is:

-0.00 0.00
4"  0.00 0.00
1⸮56'34"  0.00 ovf
[qM⸮
⸮⸮z⸮⸮⸮)⸮sA⸮⸮⸮n⸮⸮⸮⸮⸮⸮⸮?⸮o⸮⸮⸮⸮⸮⸮⸮⸮ ⸮⸮X⸮+o⸮⸮R⸮⸮⸮;⸮⸮⸮⸮w⸮⸮
^⸮⸮⸮/ټ=⸮; 0.00 -0.09
?⸮o⸮⸮⸮⸮⸮⸮⸮⸮ ⸮⸮X⸮+o⸮⸮R⸮⸮⸮;⸮⸮⸮⸮w⸮⸮
^⸮⸮⸮/ټ=⸮; ovf nan
⸮⸮w⸮⸮
^⸮⸮⸮/ټ=⸮; 0.00 ovf

Now can you help me?

Which arduino are you using? Compiling that for an Uno I get a warning that:

Low memory available, stability problems may occur.

One easy way to get more free RAM is to use the F macro on your serial.prints e.g.:

          Serial.println(F("O ficheiro 'objetos' foi encontrado!"));

And if you do have low memory to start with, use of malloc is asking for trouble.

wildbill:
Which arduino are you using? Compiling that for an Uno I get a warning that:

Low memory available, stability problems may occur.

One easy way to get more free RAM is to use the F macro on your serial.prints e.g.:

          Serial.println(F("O ficheiro 'objetos' foi encontrado!"));

And if you do have low memory to start with, use of malloc is asking for trouble.

How i do this without malloc? I dont know... this is the only way i know.

The usual solution is to declare a static array of structs up front with the maximum size you will permit the system to load from the SD card. Malloc helps you save RAM if the actual number is less than the maximum, but it will crash if you try to load too many so you may as well fix the size up front.

If you really do want to be able to process an arbitrary number of celestial objects, you can just go back to the SD card and read them one or two at a time every time you need them. You might build up an array of each line's start position in the file to help you seek() them faster.

Or, you can get a device with more RAM such as a Teensy or a Mega (assuming you're not already).

I notice too that you are using Strings. They're a death knell for your sketch if you indeed are short on RAM and likely so even if you aren't. Use of those combined with malloc is even worse. Use plain old null terminated C strings instead.