how to use malloc in arduino

Hello. I have a question, i need to use malloc in a arduino project to allocate memory for a specific struct, i understand the basic of the malloc command but i dont see how to integrate it in my project, here is the code and the file that i need to open.
The code bassicaly reads a set of locations from a file called local and saves the coordinates and the name of the places in a struct.

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

File printFile;
String Linha, Lat, Long, Name, Aux = "";
boolean SDfound;
int x, count=0, nloc=0, aux=0, meme=0;

typedef struct local_s{
 char nome[30];
 float lat;
 float lon;
 } local;

local preenche(){
  local l; 
  l.lat=Lat.toFloat();
  l.lon=Long.toFloat();
  Name.toCharArray(l.nome, 30);
  return l;
}



void setup() {
  Serial.begin(9600);

  if (!(SD.begin (4))) {
    if (!SD.begin(53)) {
      Serial.print("The SD card cannot be found");
      while(1);
    }
  }
  printFile = SD.open("local.txt");

  if (!printFile) {
    Serial.print("The text file cannot be opened");
    while(1);
  }

while (printFile.available()) {  
    Linha = printFile.readStringUntil('\n');
    nloc++;
  }
  printFile.close();
  
local tab[nloc];

 printFile = SD.open("local.txt");

  if (!printFile) {
    Serial.print("The text file cannot be opened");
    while(1);
  }


  while (printFile.available()) {  
    Linha = printFile.readStringUntil('\n');
    
    for (x=0; x<Linha.length();x++){
    if (Linha[x]!=' ' || count==2){
    Aux += Linha[x];
    }
    if (Linha[x]==' '){
    if (count==1){
    Lat=Aux;
    count=2;
    Aux = "";
    }
    if (count==0){
    Long=Aux;
    count=1;
    Aux = "";
    }
    }
    if (x==(Linha.length()-1)){
    Name=Aux;
    count=0;
    Aux = "";
    }
}
tab[aux]=preenche();
aux++;
  }
    printFile.close();
    Serial.println();
    Serial.print("Tem um total de: ");
    Serial.print(nloc);
    Serial.print(" locais.");
    Serial.println();

}

void loop() {
  while  (meme==0){
    local tab[nloc];
    for (x=0; x<nloc; x++){
      Serial.println(tab[x].nome);
      Serial.println(tab[x].lat);
      Serial.println(tab[x].lon);
    }
    meme=1;
  }
  
}

local.txt (171 Bytes)

i need to use malloc in a arduino project to allocate memory for a specific struct

Could you please explain what you are doing in more detail and why exactly you need to use malloc ?

malloc, in Arduino, works EXACTLY as it does on any other platform. Google "malloc" and you'll have thousands of articles and tutorials explaining its use in as much detail as you could possibly need.

Regards,
Ray L.

i understand the basic of the malloc command but i dont see how to integrate it in my project

If you know what malloc() does, it should be very obvious when and where to call it.

However, malloc()'s success depends on there actually being memory available to allocate. There is a fixed amount of memory available. You are far better off knowing how many instances of the struct you can create, and forget any nonsense about being able to allocate more than that.

When you know how many you can handle, just make a global array of that size.