return char data types

Try using [SafeStrings](http://ml SafeString library) then
if (dID == "CF") works as expected.
Also radio does not return a null terminated char[] so you should terminate yourself as shown below
Also in your original code you used
const char* sID = " ";
but then later changed the data in sID, so not const

Some example SafeString code

// download SafeString library from Arduino library manager
// or from the tutorial page
// https://www.forward.com.au/pfod/ArduinoProgramming/SafeString/index.html
#include "SafeString.h"

const size_t MAX_LEN = 20;
const char* src_ID = "CF";
cSF(sID, 5); // createSafeString short hand is cSF
cSF(dID, 5);
cSF(messageFromPC, MAX_LEN);

char buf[MAX_LEN + 1]; // allow space for '\0'
size_t len = MAX_LEN;
void loop() {

  if (rf95.recv(buf, &len))  {  // buf not automatically terminated
    buf[len] = '\0'; // terminate it
    cSFPS(sfBuf, buf, len); // create SafeString from the char[] buf with length len
    Serial.print("Got: "); Serial.println(sfBuf);
    int startIdx = 0;
    int endIdx = sfBuf.indexOf(',');
    sfBuf.substring(messageFromPC, startIdx, endIdx);
    if (endIdx < 0) {
      return; // error
    }
    startIdx = endIdx + 1;
    endIdx = sfBuf.indexOf(',', startIdx);
    sfBuf.substring(sID, startIdx, endIdx); //     >> this should be getting the alphabet "GT"
    if (endIdx < 0) {
      return; // error
    }
    startIdx = endIdx + 1;
    endIdx = sfBuf.indexOf(',', startIdx);
    sfBuf.substring(dID, startIdx, endIdx); // >> this should be getting the alpahbet "CF"

    if (dID == "CF") // this works using SafeStrings
    {
      cSF(data, 25);
      data.print("P,");
      data.print(src_ID);
      data.print(",");
      data.print(",Yes");
      rf95.send(data.c_str, data.length() + 1); // +1 ?? trying to send the '\0'
      rf95.waitPacketSent();
      Serial.println(data);
      Serial.println("This node is destination node");
    }
  }
}

I mean, I wanted to append char on the R part:

 sprintf(data,"V,%s,%s,Hello,R:%s",src_ID,sID);

I am not sure what should I put to do that,which it becomes R:%s%s, but I want it to be automatically append instead of manually coding it one by one because the transmission round is unknown for this case.

Not sure what you mean, can you provide some examples of the chars and the required data result.

for this :

const char* src_ID = “GT”;
const char* sID = "CF"

sprintf(data,"V,%s,%s,Hello,R:%s",src_ID,sID);

I want to append the similar char types "UT" at the R:%s
So I am trying to ask what should I do for that?

You have not answered the question in my Reply #14 of why you are using pointers the way you are. Do you not see the compiler warnings? If not, go to File -> Preferences and set "Compiler Warnings" to "All".

Not that I use sprintf myself but try

char extraData[] = "UT"
sprintf(data,"V,%s,%s,Hello,R:%s",src_ID,sID,extraData);

gfvalvo:
You have not answered the question in my Reply #14 of why you are using pointers the way you are. Do you not see the compiler warnings? If not, go to File -> Preferences and set "Compiler Warnings" to "All".

Owh I actually changed to what you suggested:

char sID [3];
char dID[3];

It is going well as of now. I don't see any warning for that.
Thanks for suggesting!

stephanie9:
for this :

const char* src_ID = “GT”;

const char* sID = "CF"

sprintf(data,"V,%s,%s,Hello,R:%s",src_ID,sID);




I want to append the similar char types "UT" at the R:%s 
So I am trying to ask what should I do for that?

The simplest option might be to just define another (larger?) buffer and sprintf into that. For example:
char bigData [50];
sprintf (bigdata, "%s, R:, %s", data, sID);

just define another (larger?) buffer

Welcome to the problems of using c-string methods.
If the 'larger' buffer is not large enough, your code is likely to just blow up and continually reset with no hint as to where the problem is.
See this posting for an example of that Use of string char causes Arduino code to restart

On the other hand using SafeStrings you will get a detailed error message about the problem and the code will continue to run, just without the overflow data.

Arduino Strings is another safe option. See my tutorial on Taming Arduino Strings - How to avoid memory issues

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.