user11957: For the below code snippet
const char* fr_fbdb(char tag[30]) // fn for retrieving data 
{
  char full_path[120]; 
  const char *_dt ; 
  strcpy(full_path , base_path);
  strcat(full_path , tag);
  Serial.print( "retrieving from " ); 
  Serial.println(full_path) ; 
  Firebase.get(firebaseData, full_path);
  _dt = firebaseData.cstrData();
//  Serial.print("while ext: "); 
//  Serial.println(_dt); 
  return _dt ; 
} 

void retreive_sch()
{
  int no_tag = strlen(*tag) ;
  //Serial.print("no. of tags in the DB: ");
  //Serial.println(no_tag);
  const char *_data[no_tag];


  Firebase.get(firebaseData, "/SCHEDULE DETAILS/SELECTED");
  sch_no = firebaseData.cstrData();

  Serial.print("extracting schedule");
  Serial.println(sch_no);

  strcat(base_path , sch_no); // base path w/ sch no.

  for (int i = 0 ; i < 6 ; i++) 
  {
    _data[i] = fr_fbdb(tag[i]); 
    Serial.print("while ext: "); 
    Serial.println(_data[i]);  
    
  }

  for(int i=0 ; i<6 ; i++)
  {
    Serial.print("after extraction:"); 
    Serial.println(_data[i]) ;
  }
}

This is the output:
retrieving  schedule changes -- setup 
extracting schedule3
retrieving from /SCHEDULE DETAILS/SCHEDULE3/DATE
while ext: [1609612200000,\"inf\"]
retrieving from /SCHEDULE DETAILS/SCHEDULE3/FREQ FR
while ext: \"-2\"
retrieving from /SCHEDULE DETAILS/SCHEDULE3/FREQ TO
while ext: \"-2\"
retrieving from /SCHEDULE DETAILS/SCHEDULE3/WEIGHT
while ext: 29
retrieving from /SCHEDULE DETAILS/SCHEDULE3/TIME
while ext: \"6:30\"
retrieving from /SCHEDULE DETAILS/SCHEDULE3/frequency
while ext: \"-1\"
after extraction:"root":[]
after extraction:\"-1\"
after extraction:keep-alive
after extraction:\"-1\"
after extraction:"root":[]
after extraction:\"-1\"

As you can see, the output of the same variable _data[] inside that particular function changes.
Any idea why?

user46852: The problem is these lines of code in your function fr_fddb():
  Firebase.get(firebaseData, full_path);
  _dt = firebaseData.cstrData();

You didn't share enough code to make this clear, but firebaseData appears to be a global which you reuse. When you call its .cstrData() method you're getting a pointer to the same buffer each time, and that buffer is overwritten each time you call Firebase.get().
You can verify this by printing the pointer value each time through, like so in your retrieve_sch() function:
  for (int i = 0 ; i < 6 ; i++) 
  {
    _data[i] = fr_fbdb(tag[i]); 
    Serial.print("while ext: "); 
    Serial.println(_data[i]);  
    Serial.printf("_data[i] pointer %p\n", _data[i]);
  }

You'll likely see that the 6 pointers are identical. The value is changing because you keep reusing the same string.
The easy fix is:
  Firebase.get(firebaseData, full_path);
  _dt = strdup(firebaseData.cstrData());

This allocates memory and stores in it a duplicate of the string that was fetched from Firebase. Your function will now return that and firebaseData can safely be reused.
This solution will require you to free that memory at some point when you're doing using it by calling free(_dt); or whatever you're holding the pointer in when you're done. I leave that as an exercise for you.

11957: <p>For the below code snippet</p>
<pre><code>const char* fr_fbdb(char tag[30]) // fn for retrieving data 
{
  char full_path[120]; 
  const char *_dt ; 
  strcpy(full_path , base_path);
  strcat(full_path , tag);
  Serial.print( &quot;retrieving from &quot; ); 
  Serial.println(full_path) ; 
  Firebase.get(firebaseData, full_path);
  _dt = firebaseData.cstrData();
//  Serial.print(&quot;while ext: &quot;); 
//  Serial.println(_dt); 
  return _dt ; 
} 

void retreive_sch()
{
  int no_tag = strlen(*tag) ;
  //Serial.print(&quot;no. of tags in the DB: &quot;);
  //Serial.println(no_tag);
  const char *_data[no_tag];


  Firebase.get(firebaseData, &quot;/SCHEDULE DETAILS/SELECTED&quot;);
  sch_no = firebaseData.cstrData();

  Serial.print(&quot;extracting schedule&quot;);
  Serial.println(sch_no);

  strcat(base_path , sch_no); // base path w/ sch no.

  for (int i = 0 ; i &lt; 6 ; i++) 
  {
    _data[i] = fr_fbdb(tag[i]); 
    Serial.print(&quot;while ext: &quot;); 
    Serial.println(_data[i]);  
    
  }

  for(int i=0 ; i&lt;6 ; i++)
  {
    Serial.print(&quot;after extraction:&quot;); 
    Serial.println(_data[i]) ;
  }
}
</code></pre>
<p>This is the output:</p>
<pre><code>retrieving  schedule changes -- setup 
extracting schedule3
retrieving from /SCHEDULE DETAILS/SCHEDULE3/DATE
while ext: [1609612200000,\&quot;inf\&quot;]
retrieving from /SCHEDULE DETAILS/SCHEDULE3/FREQ FR
while ext: \&quot;-2\&quot;
retrieving from /SCHEDULE DETAILS/SCHEDULE3/FREQ TO
while ext: \&quot;-2\&quot;
retrieving from /SCHEDULE DETAILS/SCHEDULE3/WEIGHT
while ext: 29
retrieving from /SCHEDULE DETAILS/SCHEDULE3/TIME
while ext: \&quot;6:30\&quot;
retrieving from /SCHEDULE DETAILS/SCHEDULE3/frequency
while ext: \&quot;-1\&quot;
after extraction:&quot;root&quot;:[]
after extraction:\&quot;-1\&quot;
after extraction:keep-alive
after extraction:\&quot;-1\&quot;
after extraction:&quot;root&quot;:[]
after extraction:\&quot;-1\&quot;
</code></pre>
<p>As you can see, the output of the same variable <code>_data[]</code> inside that particular function changes.
Any idea why?</p>
 46852: <p>The problem is these lines of code in your function <code>fr_fddb()</code>:</p>
<pre><code>  Firebase.get(firebaseData, full_path);
  _dt = firebaseData.cstrData();
</code></pre>
<p>You didn't share enough code to make this clear, but <code>firebaseData</code> appears to be a global which you reuse. When you call its <code>.cstrData()</code> method you're getting a pointer to the same buffer each time, and that buffer is overwritten each time you call <code>Firebase.get()</code>.</p>
<p>You can verify this by printing the pointer value each time through, like so in your <code>retrieve_sch()</code> function:</p>
<pre><code>  for (int i = 0 ; i &lt; 6 ; i++) 
  {
    _data[i] = fr_fbdb(tag[i]); 
    Serial.print(&quot;while ext: &quot;); 
    Serial.println(_data[i]);  
    Serial.printf(&quot;_data[i] pointer %p\n&quot;, _data[i]);
  }
</code></pre>
<p>You'll likely see that the 6 pointers are identical. The value is changing because you keep reusing the same string.</p>
<p>The easy fix is:</p>
<pre><code>  Firebase.get(firebaseData, full_path);
  _dt = strdup(firebaseData.cstrData());
</code></pre>
<p>This allocates memory and stores in it a duplicate of the string that was fetched from Firebase. Your function will now return that and <code>firebaseData</code> can safely be reused.</p>
<p>This solution will require you to free that memory at some point when you're doing using it by calling <code>free(_dt);</code> or whatever you're holding the pointer in when you're done. I leave that as an exercise for you.</p>
