Please help me convert this from String to char

I've been having a discussion in another post about variable types. Forgive me, I'm a noob. The good news is that the forum helped me get this script functioning. It subscribes. It publishes. It does what it needs to do. The bad news, is that after two days, I could not get this to work using the variable type char.

Only String. Which everyone says is a bad idea.  Can someone help me convert this so that lines 6,7, 8,9 
String campus = "campus";
String building = "building";
String room = "office";
String subscription = campus+'/'+building+'/'+room+'/'+'#';

are variable type string and about half way down my function

      client.subscribe(subscription.c_str());

Still works?

Here's my entire diagnostic script:

#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#define DEVICE "OfficeArduino"
#define DEVICEHELLO "OfficeArduino Connected"
String campus = "campus";
String building = "building";
String room = "office";
String subscription = campus+'/'+building+'/'+room+'/'+'#';
float setpoint = 45.00;
float actual = 44.44;
int state = 0;
int request = 0;

char *cstring;
byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 221);
IPAddress server(192, 168, 0, 222);

void callback(char* topic, byte* payload, unsigned int length) {
  for (int i=0;i<length;i++) {
    payload[length] = '\0';

    cstring = (char *) payload;
  }
    Serial.println(topic);
    Serial.println(cstring);
    setpoint = atof(cstring);
    Serial.println("The setpoint is...");

}

EthernetClient ethClient;
PubSubClient client(ethClient);

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect(DEVICE)) {
      Serial.println("connected");
      // Once connected, publish an announcement...
      client.publish("outTopic",DEVICEHELLO);
      // ... and resubscribe
      client.subscribe(subscription.c_str());
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}


void setup()
{

 // disable SD card if one in the slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  Serial.begin(57600);

  client.setServer(server, 1883);
  client.setCallback(callback);

  Ethernet.begin(mac, ip);
  // Allow the hardware to sort itself out
  delay(1500);

}

void loop()
{
  if (!client.connected()) {
    reconnect();
  }
  client.loop();
}

Just let the compiler do the concatenation for you, no need for Strings:

#define CAMPUS "campus"
#define BUILDING "building"
#define ROOM "office"

const char* subscription = CAMPUS "/" BUILDING "/" ROOM "/#";

// ... 

      client.subscribe(subscription);

// ...

The preprocessor will just replace all occurrences of CAMPUS, BUILDING and ROOM by their definitions, so the fifth line becomes:

const char* subscription = "campus" "/" "building" "/" "office" "/#";

When you have multiple string literals right next to each other, they will just be concatenated:

const char* subscription = "campus/building/office/#";

This string literal is saved in memory as an array of characters (chars), so we need a pointer to a char as data type (char *). The value is read-only, so you can make it a const char *.

Pieter

This seems a lot simpler that what I was trying. I'm still having a few issues.

#define CAMPUS "campus"
#define BUILDING "building"
#define ROOM "office"

const char* subscription = CAMPUS "/" BUILDING "/" ROOM "/#";

throws the error
expected ',' or ';' before 'BUILDING'

on the concatenation.

Changing the double quotes to single quotes gives
expected ',' or ';' before '/'

Any advice? Thanks so much for your time!

I showed you, in your other thread, how to use the string functions to create an initial string, and concatenate the rest of the stuff. You claimed to have tried that, and to have had some problems about which you did nothing but wave your arms uselessly.

Show that code and the complete error message(s). There might have been a typo or a misplaced " or ) or ;. You might have made the typo/mistake, or I might have.

mudmin:
This seems a lot simpler that what I was trying. I'm still having a few issues.

#define CAMPUS "campus"

#define BUILDING "building"
#define ROOM "office"

const char* subscription = CAMPUS "/" BUILDING "/" ROOM "/#";




throws the error
expected ',' or ';' before 'BUILDING'

on the concatenation.

Changing the double quotes to single quotes gives 
expected ',' or ';' before '/'

Any advice? Thanks so much for your time!

It compiles perfectly fine for me.
Unless you show us the exact code and error messages, and you tell us what board settings you are using, there's nothing we can do to help.

Pieter

Yeah. It was a weird. It wouldn't compile until I made some other changes to the code and then it finally compiled. I wish I could give you more information, but it just kinda started working and I'm not sure why.