Home:ALL Converter>Converting String style from Arduino to C common style

Converting String style from Arduino to C common style

Ask Time:2013-05-11T02:34:31         Author:mafap

Json Formatter

I have the following code

void loop() {
  String outMessage = "";  // String to hold input

  while (Serial.available() > 0) {  // check if at least one char is available
    char inChar = Serial.read();
    outMessage.concat(inChar);  // add Chars to outMessage (concatenate)
  }

  if (outMessage != "") {
    Serial.println("Sent:  " + outMessage); // see in Serial Monitor
    Serial1.write(outMessage); // Send to the other Arduino
  }

and I want to write it in the common C language.

The Arduino String class, part of the core as of version 0019, allows us to use and manipulate strings of text in more complex ways than character arrays do.

I don't know what way is better for programming. The only thing I know is that String takes a lot of memory. Any sugestion?

Author:mafap,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/16488735/converting-string-style-from-arduino-to-c-common-style
user529758 :

There's no such thing as \"the Arduino language\". Arduinos (well, rather the AVRs inside) are programmed using C, C++ or assembler, and the Arduino core library provides some C functions (along with AVR-libc) and C++ classes for common tasks. What you are actually trying to do here is transforming your code from C++ to C.\n\nSpecifically, in C, strings are 0-terminated arrays of char, so you could do something like this:\n\nchar welcome[] = \"Hello world!\";\n\n\nMoar...",
2013-05-10T18:39:16
yy