Help with connecting two strings

Hello!

I am a total newbie to Arduino coding and just trying to piece two sketches together for the first time: one that takes a reading from a temp sensor, and a second that tweets from Arduino via the wifi shield.

I am running into problems on line 26 with the error: 'class String' has no member named 'c_str'

Any guidance on how to make it work? Code is below.

thanks!
Will

#include <SPI.h>
#include <stdlib.h>
#include <WiFi.h>
#include <Twitter.h>
int outputpin= 0;

char ssid[] = "X"; // your network SSID (name)
char pass[] = "X"; // your network password
char temp[6];
String msg = "It is this many degrees Kelvin at my house: ";

Twitter twitter("X");

void setup()
{
Serial.begin(9600);
delay(1000);
WiFi.begin(ssid, pass);
delay(10000);
int rawvoltage= analogRead(outputpin);
float kelvin;
float millivolts= (rawvoltage/1024.0) * 5000;
kelvin= (millivolts/10);
dtostrf(kelvin, 3, 3, temp); //4 is mininum width, 3 is precision; float value is copied onto buff
msg.concat(temp);
Serial.println("connecting ...");
if (twitter.post(msg.c_str)) {
int status = twitter.wait(&Serial);
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}

void loop()
{
}

The error message seems very informative.

 if (twitter.post(msg.c_str)) {

What are you trying to do in this line apart from sending the message in the msg String to Twitter ?

To be honest, I'm not sure what that line is doing. Someone else suggested it as a possible fix.

A fix to what ?

Did they perhaps suggest using a C style string instead of a String ?

If you want to use C strings then why not just do it and forget about Strings ?

In the meantime try

if (twitter.post(msg.c_str()))

@Delta_G - thanks that did the trick!

The final code is below. I will post the link to my write-up when its ready. Thanks all!

#include <SPI.h>
#include <stdlib.h>
#include <WiFi.h> // arduino wifi libnrary
#include <Twitter.h> //ardiono twitter library
int outputpin= 0;

char ssid[] = "XXX"; // your network SSID (name)
char pass[] = "XXX"; // your network password
char temp[6];
char msg[50] = "It is this many degrees Kelvin at my house: ";

Twitter twitter("XXX);

void setup()
{
Serial.begin(9600);
delay(1000);
WiFi.begin(ssid, pass);
delay(10000);
int rawvoltage= analogRead(outputpin);
float kelvin;
float millivolts= (rawvoltage/1024.0) * 5000;
kelvin= (millivolts/10);
dtostrf(kelvin, 3, 3, temp); //4 is mininum width, 3 is precision; float value is copied onto buff
strcat(msg, temp);
Serial.println("connecting ...");
if (twitter.post(msg)) {
int status = twitter.wait(&Serial);
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}

void loop()
{
}

dtostrf(kelvin, 3, 3, temp);  //4 is mininum width, 3 is precision; float value is copied onto buff

Why are you expecting to get some digits before the decimal point, a decimal point, and three digits after the decimal point in a 3 character wide output?

I suspect that your 6 character array is not wide enough, unless it is a very cold day where you are.

Welcome to the Forum. Before your next post, please read Nick Gammon's two posts at the top of this Forum for guidelines on posting here, especially about the use of code tags when listing programs. It will help us help you. Also, if you look at the code size with String (i.e., the C++ class) versus string (i.e., using a char array), I'll bet the latter is considerably smaller. The String class may seem convenient, but it is very costly in terms of resource use.

Hi all - I got everything to work and finally wrote it up into this tutorial:

Thanks for your help with the code!