Questions tagged [c-string]

A "C string" is an array of characters that ends with a 0 (null character) byte. The array, not any pointer, is the string.

A "C string" is an array of characters that ends with a 0 (null character) byte. The array, not any pointer, is the string.

28 questions
17
votes
1 answer

Convert int to char[]

I'm looking to convert an int value to a char array. currently I've found the following will return [number] int num = [number] str = String(num); str.toCharArray(cstr,16); Serial.println(cstr); However, per Majenko's The Evils of Arduino Strings I…
ATE-ENGE
  • 941
  • 3
  • 19
  • 32
12
votes
6 answers

Using String instead of C string, yet another attempt to touch a loaded issue

I've been reading a lot over the years why we should not use the notorious String class and how heap fragmentation is bad practice and not professional and we should never use it in our programs or we'll never enter the C hall of fame and get to be…
Nino
  • 411
  • 4
  • 9
10
votes
5 answers

formatting strings in Arduino for output

I wander what is the best option for formatting strings in Arduino for output. I mean what's a preferable way in the point of view of performance, memory usage – things like that. I see, people usually use direct Serial.print/println, like this: …
zhekaus
  • 459
  • 2
  • 6
  • 18
3
votes
2 answers

Problems on convert byte[] to String

I'm reading a RFID Card from RC522 and send the data to my computer. My problem is the conversion of byte[] to String or std::string. #define SIZE_BUFFER 18 #define MAX_SIZE_BLOCK 16 byte buffer[SIZE_BUFFER] = {0}; byte tam = SIZE_BUFFER; //…
Augusto
  • 131
  • 1
  • 1
  • 5
2
votes
1 answer

Using c_str() on String for IPAddress with NTPClient provides wrong values

Libraries NTPClient Board Olimex ESP32-POE board Behaviour I have written a code that connects the board to a local NTP Server (which is an embedded board). I tried assigning the IP Address of the above NTP Server using IPAddress and then convert…
Shan-Desai
  • 179
  • 3
  • 19
1
vote
1 answer

Parse char* mac-string to uint8_t array

I have to handle a String coming in over UART containing a bunch of information, part of it is a MAC-address that I get by using String.substring(a, b) returning a 12-char String representing a mac-address "B8C9A45BA770" <- (just an example). I need…
1
vote
2 answers

When Writing Library, return String or return char *

I am trying to write my own Arduino library and I would like to make it useful not just for ESP32/ESP8266 boards but also with Arduino boards. I have created my header file like this test.cpp #ifndef TEST #define TEST #include "Arduino.h" #define…
Mark Estrada
  • 243
  • 2
  • 8
1
vote
2 answers

Arduino - Function -> return Cstr instead of string

I have following function for my Arduino: String readLine() { String received = ""; char ch; while (myFile.available()) { ch = myFile.read(); if (ch == '\n' or ch == '\r') { if (ch == '\r') { //get rid of the \n …
sharkyenergy
  • 125
  • 4
1
vote
2 answers

strcmp doesn't seem to work

I'm trying to compare a char array that I'm assembling to a string and I'm having trouble comparing the strings. I'm getting the data for the char array as a set of bytes and I'm compiling it into a char array like this: void messageHandler(char…
Chris Schmitz
  • 357
  • 6
  • 18
1
vote
2 answers

Read Comma Separated String

I have a string that looks like this "10.00,20.00,-50.00," in which these are angle values and they have 2 decimals and can be negative. I want to separate them into 3 separate floats. Here is my current code in which I use sscanf. All I get is 0.00…
DragonflyRobotics
  • 313
  • 1
  • 4
  • 20
1
vote
0 answers

Conversion from string to char array

I know this is Arduino Forum but I think this question is related to programming, I am using ESP8266 for the project. I need to convert the string incoming on the serial through UART lines and receiving those using the below code. Also I am…
Naren2312
  • 11
  • 1
1
vote
1 answer

Yet another basic and silly question about C++ strings

I made a sketch like this: void setup() { // put your setup code here, to run once: Serial.begin(9600); char str1[64] = "test with spaces"; char str2[32] = "test with spaces"; Serial.println(str1); Serial.println(str2); if (str1 ==…
MrCabana
  • 61
  • 4
1
vote
1 answer

Char* and string conversion from an ESP8266 web server

I have the following Arduino code for configuring a wifi connection through a simple webpage: I declare char* ssid;. Later I read a value from a SPIFFS config file where q_ssid is declared as a string and successfully populated from the…
0
votes
2 answers

String() vs char for simple flow control

I am newbie in Arduino and writing a program where I want to control the flow by using Serial monitor input (PI controller). I've read that using String() although easier it is slower than using char. But to use char I would need more lines of code…
0
votes
1 answer

String operations printing random character on Serial Monitor

I want to extract the file name MyFile.txt out of a path which is stored in a string "C:\\MyDirectory\\MyFile.txt"; I found a simple c code which does the job. string filename = "C:\\MyDirectory\\MyFile.bat"; // Remove directory if present. // Do…
1
2