how to convert a string into a char?

Hi all, I'm using thi sibrary to post on twitter.

http://www.arduino.cc/playground/Code/TwitterLibrary

Is easy to use, but It accept only char for twitting, and i'm able to compose texts and sensors values only with string. There is a way to convert a string into a char? I did many search but seems to be a difficult point. Thank you all...

Is easy to use, but It accept only char for twitting

This is not true. It posts arrays of characters, not single characters.

i'm able to compose texts and sensors values only with string.

Again, not true. There are ways to create character arrays containing data from sensors.

A string (lower case s) is simply a NULL terminated array of characters.

A String (upper case s), on the other hand, is a poorly written wrapper around the string concept.

A string (multiple characters) can not be converted, meaningfully, to a char (a single character).

Post your code, so we can help you choose the appropriate data type and formatting functions.

Thank you, this is my code.
I know I’m not very expert about but i hope in your help.

#if defined(ARDUINO) && ARDUINO > 18   // Arduino 0019 or later
#include <SPI.h>
#endif
#include <Ethernet.h>
#include <EthernetDNS.h>
#include <Twitter.h>

// Ethernet Shield Settings
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x77, 0x5D };
byte ip[] = { 10,163,13,115 };

// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("395212348-ahJnSbYm8auM40gvBoAJRlMBOsJc11lkIGlYtSQk");

//sensors i would like to use to tweet



void setup()
{
  delay(2000);
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  }

void loop()
{
  char msg[] = "Hello World!";

int sensorOne =analogRead(A0);
int sensorTwo =analogRead(A1);

String tweet= "";
tweet = tweet + "the data from sensor one is: "+ sensorOne + ", and from the sensor two is: " + sensorTwo;
  Serial.println(tweet);

  
  
    Serial.println("connecting ...");
  if (twitter.post(msg)) {                                           //it work only with "msg" that is a char, i would like to use "tweet"
 
    int status = twitter.wait(&Serial);
    if (status == 200) {
      Serial.println("OK.");
    } else {
      Serial.print("failed : code ");
      Serial.println(status);
    }
  } else {
    Serial.println("connection failed.");
  }
  delay(60000);

}

There is a way to convert Strings to char buffers. But the better way is not use String in the first place.

Mmm, so what's the way or how can i can compose a char as i do with String?

http://www.arduino.cc/en/Tutorial/TextString

The String class has a method, toCharArray(), that can be used to get the character array from the String.

int strLen = tweet.length(); // Get the length
char *msg = (char *)malloc(strLen+1); Allocate space to hold the data
if(msg)
{
   tweet.toCharArray(msg, strLen+1);

   // Send the data in msg to twitter

   free(msg);
}

Or, you could use sprintf() to create an array of chars with formatting:

char msg[64];
sprintf(msg, "Sensor 1: %d; Sensor 2 %d", sensorOne, sensorTwo);
// Send the data in msg to twitter

Thank you, they work both.

Just two questions about the second method:

-why the [64] as values of the char?

-can i also insert other char or String in place of a Int inside the composition? Because seems to don't work in thats way.

why the [64] as values of the char?

There needs to be some size. I picked 64 because it's not too large and not too small.

can i also insert other char or String in place of a Int inside the composition?

If you change the format specifier, yes, you can use some other types. %d is for ints. %s would be for strings (NULL terminated array of char). Strings are not a native type, so the toCharArray() method need to be used to extract the native type.

Thank you, seems to work now. ;-)