Timeline for Regarding Strings and assignments
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 9, 2020 at 17:15 | comment | added | Majenko | cplusplus.com/reference/cstring/strncpy | |
| Apr 9, 2020 at 17:15 | comment | added | Majenko | No, you just won't get a null terminator. | |
| Apr 9, 2020 at 17:13 | comment | added | Codebreaker007 | Yes clear with the example of "ok" but if I do "first" wouldn't that write out of bounds -since that could be a problem for general usage of strncpy Thanks for your time | |
| Apr 9, 2020 at 17:09 | comment | added | Majenko | No. The 5 includes the terminator if there is one within the first 5 bytes. But even then, it will only do 3 bytes anyway since it stops on the NULL before it reaches the limit of 5. | |
| Apr 9, 2020 at 17:07 | comment | added | Codebreaker007 | @majenko Sorry to be questioning but wouldn't strncpy(ErrorMsg, "OK", 5); write the terminator out of bounds, shouldn't it be strncpy(ErrorMsg, "OK", 4); for a char[5] ? As I normally do it like strncpy(ErrorMsg, "OK", strlen (ErrorMsg)-1) to be on the safe side | |
| Apr 9, 2020 at 15:17 | comment | added | EmbSysDev | Very nice blog indeed. Arduino is a wonderful tool;but it does seem to help you mess up bigtime. I guess like everyhing else, one learns by first messing up | |
| Apr 9, 2020 at 15:08 | comment | added | Majenko |
@EmbSysDev I have a small blog post about replacing String with C strings. majenko.co.uk/blog/evils-arduino-strings
|
|
| Apr 9, 2020 at 15:07 | comment | added | EmbSysDev | Terrific , Majenko,exactly what I was looking for ! | |
| Apr 9, 2020 at 14:54 | comment | added | Majenko |
Into a suitably sized char buffer? Yes. strcpy replaces the string content from the start. strcat concatenates more content on to the end. strcpy(buffer, "<h1>Programming</h1><h2>"); strcat(buffer, ErrorMsg); strcat(buffer, " Programming Over "); ...
|
|
| Apr 9, 2020 at 14:46 | comment | added | EmbSysDev | Thanks Majenko. Is there a way to do do something like : String flashhtml = "<h1>Programming</h1><h2>" + ErrorMsg + " Programming Over " ; Something similar to concatenating multiple fixed strings and variable strings ? I know there are other ways to do this , but i was looking for the simplest possibility. | |
| Apr 9, 2020 at 14:34 | history | answered | Majenko | CC BY-SA 4.0 |