Skip to main content

Timeline for Convert C string to C++ string

Current License: CC BY-SA 4.0

21 events
when toggle format what by license comment
Feb 10, 2020 at 19:22 vote accept Marius Wanscher
Feb 10, 2020 at 19:14 vote accept Marius Wanscher
Feb 10, 2020 at 19:22
Feb 1, 2020 at 4:18 history edited dda CC BY-SA 4.0
added 5 characters in body; edited title
Jan 31, 2020 at 21:01 history bumped CommunityBot This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
S Jan 1, 2020 at 20:05 history suggested Peter Paul Kiefer CC BY-SA 4.0
code formatting
Jan 1, 2020 at 19:06 answer added Marius Wanscher timeline score: 0
Jan 1, 2020 at 19:04 comment added Peter Paul Kiefer Sorry, now I understand what you tried. Yes it's part of the ESP32 software. And you might not want to store the date in EEPROM, just make it persistent while deep sleep. (I think I should go to sleep now ;-) ) randomnerdtutorials.com/esp32-timer-wake-up-deep-sleep @Juraj gave you the solution. But the null pointer problem is still there. Or is this not all of the code.
Jan 1, 2020 at 19:04 comment added Marius Wanscher solution found, using the strcpy, thanks
Jan 1, 2020 at 18:53 comment added Peter Paul Kiefer A null pointer is a runtime error, which you can not see at compile time. In the arduino context you will not recognize the null pointer exception. But I'm sure you get one as you initialized the BLECharacteristic *cSsid = NULL; and then used the null pointer cSsid->getValue(). Or did I missed something and NULL is an option object? Can C++ handle option objects in the meantime? But anyway whithout knowing the library I can not help you. If you just want to make your string persistent you could probably write it to the FLASH memory. randomnerdtutorials.com/esp32-flash-memory
Jan 1, 2020 at 18:52 comment added Juraj RTC_DATA_ATTR char ssid[33]; strcpy(ssid, cSsid->getValue().c_str());
Jan 1, 2020 at 18:43 comment added Marius Wanscher but all im looking for is a way to copy the value of the string from bluetooth into the RTC string, which in my head the solution should just be todo: =
Jan 1, 2020 at 18:42 comment added Marius Wanscher i would guess the RTC and Deep_sleep commands come from the installed board in ArduinoIDE
Jan 1, 2020 at 18:40 comment added Marius Wanscher it doesnt give any error, when i compile it, but in the serial monitor, it println(rtcstring) just prints clear line, as if rtc string was = null
Jan 1, 2020 at 18:39 comment added Marius Wanscher i have no idea what library the RTC is apart of, I haven't #include any library which it is in
Jan 1, 2020 at 18:38 comment added Peter Paul Kiefer Your code would lead to a null pointer exception, which will be silently skipped..
Jan 1, 2020 at 18:35 review Suggested edits
S Jan 1, 2020 at 20:05
Jan 1, 2020 at 18:35 history edited Marius Wanscher CC BY-SA 4.0
added 155 characters in body
Jan 1, 2020 at 18:34 comment added Peter Paul Kiefer I agree with @Juraj . I believe you misused the terms cstring and c++ strings. As I understand your question, you have a class RTC_DATA_ATTR that allocates its content memory (string typed) from the RTC EEPROM. Now you ask how you are able to initialize that Class with content from a "cstring". (as you use .c_str() I believe this is also a c++ string) Because I don't know the library RTC_DATA_ATTR is from I can not say how to copy text into a string of that type. You should at least add the library name to the question or give us some information what that type is like.
Jan 1, 2020 at 18:33 comment added Marius Wanscher yes, my question is: how do i copy the c string to my rtc memory
Jan 1, 2020 at 18:31 comment added Juraj you mixed it up. you want a C string from String? .c_str() of String returns a constant pointer to the internal C string (zero terminated char array) of String which is in heap. but to save it to RTC memory something must copy it to the RTC memory. it is not neccessary to copy it into 'C string' in memory.
Jan 1, 2020 at 17:51 history asked Marius Wanscher CC BY-SA 4.0