Это видео недоступно.
Сожалеем об этом.
Text String Tutorial in C Code! Tutorial using Arduino, copy/move/parsing/etc...
HTML-код
- Опубликовано: 18 авг 2024
- Just my 2 cents in how to handle and manipulate text strings (Character Arrays) in C code... all shown using Arduino, but is universal on embedded systems coded in C. Very useful stuff in here that can be used in many projects!
It's a doozy, so here are the timestamps:
2:13 Intro, Size, Length, and Null
8:10 Concatenate
10:33 Copy and Move
16:09 Comparing two strings
17:09 Find string in another string
21:06 Parsing a string, like data separated by commas
24:50 Convert string to integers, long, float and back to string
28:00 Pass and return strings with functions
29:25 Parse data from a serial port - real example
THE CODE:
www.kevindarra...
Check out my Tindie store (trigBoard is available) www.tindie.com...
Thanks to all the Patrons for dropping a few bucks in the tip jar to help make these videos happen!
/ kdarrah
Twitter: / kdcircuits
For inquiries or design services:
www.kdcircuits...
Now that folks is how to do a tutorial. No waffle, just the facts. One of the best I've seen - on any subject. Thanks a lot.
thanks - yea I make these vids for the future version of me that forgot how to do this
Great tutorial. This is one of the best Arduino tutorials I've seen. Very clear and thorough. I was having some weird bugs with the display for a testing device I've been working on. It turns out I wasn't accounting for the need for the null character! It was very fortunate that for me that you posted this and I watched it earlier this week!
The best string tutorial I've seen so far, and I've seen gobs. Thanks.
I had been looking for a concise (yet detailed enough for practical value) courses on string manipulation. This video provides almost exactly the topics I needed (basic theory, copying, parsing conversion and passing through functions).
Thanks a ton!
THANK YOU SO MUCH
20 years of hobby programming and having so much hard time with characters, especially those last years with Mqtt messages. And now every thing is clear to me!
THANK YOU AGAIN!
Your video [Cheap and Easy WiFi (IoT) Tutorial Part 2 - ESP8266 Arduino Code
] was extremely useful when I was tring to make a WIFI connected IR remote for my air-conditioning.
RUclips recommended me this video and thanks to that suggestion I found back your channel.
Your way of explaining and demonstrating stuff is in perfect sync with the way I learn.
You earn a new follower and please more of this kind of tutorial.
Brilliant presentation. Strings get me every time I come back to coding in C/C++. Your tutorial is really helpful. Thanks!
I've watched this video several times since your released it. I've got it bookmarked as everytime I pick up something new. It has been really helpful. Thank you!
I've been playing with Arduino for some time now. New project that uses strings and am all at sea. This video was super helpful. Well worth the investment in time. Thanks Kevin.
Really informative and in a good teaching speed! Hope to see more! There are a lot of pitfalls when people want to step up from simple blink sketches to working with different datatypes and more „special“ functions. If you’ve never heard about it, you can’t use it.
Loved the video. Very helpful to know these functions, which when I tried Googling some of them to see what was also out there on them, I could not immediately find them online. ..You explain them well one line at a time and one lesson at a time, then putting it all together at the end. I think now I know them well enough I will be able to apply them to my own coding.
this is AMAZING basics for the newcomers - seriously! The biggest issue in the online tutorials for Arduino is: almost everybody jumps directly to String class and people start using it without knowing the background of how strings and characters work in C/C++. Then programs crash etc. Thank you again!
Yes that is exactly how to do a tutorial.....Tnx Kevin you're awesome my friend!!!!...the best on strings I've found so far!!!....
useful Video, after a long surf at internet. I appreciate your work man.
I also struggle with string manipulation on arduino. Thanks for this video.
This is super helpful, and just when I needed it. Thanks!
I came here to debug getting some GPS text to do what I want. Got stopped for a couple of days. This video info can probably get me going again.
I had been looking for it.... and here it is.... Well explained and many thanks for the code.
Very nice and Clear Video. Lesson 9 helps me alot
Succinct and yet comprehensive tutorial. Thank you. It answered a lot of questions I had.
Great job. I wish i had found this 6 months ago. Thanks for making the code available.
very nice tutorial!!! thank you!
I have used something similar with Python (of course we can not compare c++ with python) but this is the basics to understand how it works on high level languages. thank you
Very well done! After looking through more than a dozen tutorials it was awesome to find yours. This gives me the tools to build what I need for serial data pass.
I would love to see more of this kind of video, especially if it could be searched easily for each lesson. If you showed a index of lesson's and had a small number on each video frame to show what lesson your on it would be easy to fast forward to a lesson topic. Very well done.
A very high quality tutorial. He shows commands I have never found in the Arduino reference.
Thank you, Informative, great for a hobbyist like me, Lesson plans r awesome, Bless u 4 putting this info on RUclips!
Thanks for making such a well paced, well put together video, with very helpful explanations.
great and useful video again, thanks
I didn't know "Strings" are such big deal
THANK YOU thank you THANK YOU So much for this. Beautifully given lesson. Easy to understand and follow. got me up and running!
I will send a message to the arduino website to ask them to put a link to your video on their wiki.
This is an excellent video, it covered most of what I was looking for.
Thoroughly explained topic. Thanks for the video.😀
Aaaaww. Watched it when released , but today the video was very very illustrative and helpful. I copied many lines in my project I’d you don’t mind. Thanks
Thank you! Very useful stuff to use on my MQTT project!
Super helpful! Your examples are great, and everything is very sectioned out and builds up your understanding piece by piece so it's not overwhelming. Thank you!
Thanks! Really useful exploration and a great way to do it. It's bad I know, but I've always been mildly suspect of string functions and classes (not covered here) because I didn't really know what they were doing (whereas I do if I stick to my own code) but this is really useful to know what is out there and that the functions are, for the most part, just nice little helpers so long as you know what they are doing and use them carefully (those checks FTW). You also solved one of my problems. I'd hit the "ah, compiler directive" point before, took one look at about half a page of them all mashed together and thought "life is too short" - just multiplied the values into ints instead (which worked fine - but was a bit of a hack)
Hi Kevin, I've watched you and subscribed years ago, even bought a couple trig boards, but then lost track of you. I've recently tried to work with character data coming back from auto authorize app and had been looking for a tutorial on explaining strings. Yours in the first that ties all the options. Otherwise I've had to look at many examples to try to get all the options available to read back and decipher the data sent back. Thanks and I'll start fallowing you again.
I appreciate this video's high quality. Subscribed and bell'd up.
This is an excellent video, thank you very much for sharing your knowledge, I was able to solve a problem I had. Your video explains in a very deep and clear way a topic that few videos do, on the subject. Cordial greetings from Bogota / Colombia.
At last! Now I have something I can use. First rate video for a non beginner
Wow, excellent tutorial video. Very informative
Awesome in depth tutorial. Thanks!
Extremely helpful! All I'll ever need for transfering data over UART
thanks - yea one of my favorite videos I reference back to myself for UART comms
@@Kevindarrah Serial Input Basics is also very helpful forum.arduino.cc/t/serial-input-basics-updated/382007/3#example-5-receiving-and-parsing-several-pieces-of-data-3
What a GREAT string tutorial. Thanks,
atoi() ... what a nice function (if you know about it, thank you for introducing me to it!) A month or two ago I was trying to read an int over serial and I ended up writing my own function to parse a string into an integer. My version of the function lacked many safety checks I imagine... Also nice job explaining how to print a float, while I generally avoid floats, it is nice to know how to print them should I need to. Maybe the next part of this should be on adding a CRC or similar check to ensure the data all arrived without hidden errors?
Great video. Thanks! More would be great.
Excellent tutorial, learnt loads. Thanks
This is my greatest problem when working with Arduino and alike! This is a much needed piece of information. Till now I was totally confused by *,& and NULL ending chars. I was always angry why don't they use String which is much easier to shuffle around. There are so many instances you cannot use String, like your serial input example where you only get bytes in. I will start playing around and rewind the video a few times. Only thing I did not grab dierectly is searching and using NULL as a next item!
I liked this type of instructional video and would like to see more of them. I see you have started a playlist with this video, would this video alway be number 1 in the list or could it's position be altered as required in the future. Thanks PCLFW
Great tutorial man. That's what I was exactly looking for. Thanks for sharing.
EXELENTE . ESTOY SORPRENDIDO POR COMO COMENTAS TAN RAPIDO Y PRESISO.
Thank you so much!! this content is so valuable, keep it up!
Very usefull video, that I'm gonna need to see a few more times... Thanks..
This is a very good video. Thanks.
wow!! In depth explanation of the functions...
can be transferred to read from SD card instead of serial monitor by just replacing the Serial.readBytesUntil with file.readBytesUntil if the file is a SD located file?
GREAT Tutorial, easy to understand and helps a lot. Thank You 👍🏻
Thank you sir awesome tutorial.. Got what I want
Great work on char and string manipulations. Could you talk about
indexOf , trim and using substring? Many thanks.
Great JOB !! complete and clear, a Wiki to save and always keep in mind. THANK YOU
Great job... as usual.
Thanks for this video tutorial. I’ve struggled with text manipulation and this has explained problems I’ve had. I’ve watched your channel for a number of years and am always impressed with the depth and clarity of your explanations.
Have you considered doing a lesson on using Tabs with the Arduino IDE? I’ve tried using them but have ended up with “not declared” errors. I thought it would make a long sketch easier to debug if I kept the main loop short and called functions for most of the code, putting each function in a separate tap. I think my problems come when I try to call one function from another function (e.g., a function to set a clock uses a function to update the display). Should I use local or global variables? Do I create .ino, .cpp, or .h files? I’ve looked at some other videos, but I didn’t get an understanding of why they did what they did or how to decide which approach to take for my designs.
Thanks again for your videos.
I'd very much like to see a video by you explaining Tabs.
Good question. Say you want one extra "place" (aside from your .ino file) with code in, say called: "myExtraCode". For this you need 2 files: myExtraCode.h and myExtraCode.cpp. You put the full functions in myExtraCode.cpp, and, for each function you put there, you write just its definition (the top line of the function, but with a ; on the end) in myExtraCode.h. The code in your .ino file needs to know where these other functions are though, so to tell it, you'd add #include "myExtraCode.h" near the top of the .ino file. A short video on this might not be a bad idea though, especially if it went into the #ifdef stuff.
Thank for briefing so nicest way what strings are all about
It seems you generally confuse the NULL character string pointer with the ASCII Nul character string terminator throughout this video. The latter may be written as just the number 0 or the character literal '\0'. Now, this mostly works because NULL often happens to defined as 0 as well, but I believe at least in C (not in C++) it may be defined as (char*)0 or (void*)0 as well. I guess the idea of NULL was to convey the concept of the null pointer, not a specific character value, so this simply breaks that subtle distinction. In other words NULL is a _pointer_ while '\0' is a _char_ type.
Around the 33:40 mark this goes wrong when, after you print "token to big" (sic), a null pointer is passed as the source string to strcpy, which actually invokes undefined behavior. You should have passed "" (empty string) or just written the whole statement as "parsedStrings[0][0] = 0;".
good info!
I wish I would have found this early on. The idea that strings had to be stored as individual characters in an array seemed so foreign to me when I started learning C++ (coming from JS, PHP, Perl, Python - Interpreted languages). I started using the String lib with Arduino just because it made things easier, but it quickly turned to crap due to how much memory it uses up. I now stay as far away from String as I can, lol.
Very useful! Thanks!! :)
that´s what i need - thx a lot
Great video, super helpful.
thank you , it was great help very useful
Great tutorial, thanks.
In lesson 7 you were parsing strings for data. You used a fixed length. What do you do when you have to handle an unknown length? Like say you're getting input from a web page, and the input is a textarea where the user can put in whatever they want, and you have to parse it out.
Note, its better to use ‘\0’ instead of NULL
14:41 In line 36 you set the maximum length as sizeof(stringOne), but you start your copy target at &stringOne[3] . Don't you have to subtract the "3" from the sizeof(stringOne) value, otherwise the strncpy could overrun the target by 3 characters?
I don't understand why a null character is added automatically at
3:20 char charString[] = "123456789";
but in all the other surrounding examples, the null character isn't added, so you have to manually do it. What am I missing?
Any lectures on esp8266 12e and esp32 type Arduino code, would be great. For example, how to deal with multiple TCP clients and one client does or takes too long, which then delays or crashes other clients tx tx
Hey Kevin, does sprintf put a NULL character at the end of the char array ? thanks :)
Marc.
Same here. As coming from the Python world I still struggle with the way things work in C/C++, especially strings.
Don't I need to include any libraries like ios, iostream etc.?
great stuff....but sadly too late...i already needed to learn it all myself and surely i had a hard time figuring that out.
Main reason was that i wanted to code a function which put out a given text, and/or numbers - letter by letter with a slight delay on a 40x2 chars VFD display
Hi thank you for the great tutorial.
I have a question in your last lesson.
What if the rawData is dynamic ?
How to make the parsedStrings[4][20] dynamic that can hold any number of comma separated values.?
Thanks
Can you check if the code below is the best solution to my question above?
```
int count = 0;
char *ptr = rawdata;
while((&rawData[dataPosition] = strchr(ptr, ',')) != NULL) {
count++;
ptr++;
}
```
At 6:38 why is the size 100? if the length has increased to 109 then why didn't the size? And ok, if the size is fixed then how come it can go beyond its defined limit of 100 to hit a null character? Didn't get that.
when i am sending "i love you" over serial monitor its ok with code line const char msg = " i love you" but when i am sending the same stuff with the help of String msg = " i love you its giving random stuff, why?
Is it posseble to change the Function Serial.readbytesUntil() with the normal Serial.read(), because I try to connect My Arduino with Processing and will read Data from it and Processing works with Serial.read??
by the way this tutorial is very good
Super good... Thanks :)
would leave a million likes if i could... very helpful
Great vid, strings are always a pain in C, BUT why does the arduino have "atof" but stringf does not have "%f"? They give with one hand and take away with the other 8-)
I was looking into this a while ago in relation to a related function with the same problem (lack of float support). I think I read something that implied it was a space saving decision, but check that (although it seems a plausible/sensible explanation - especially to anyone who as ever run out!)
Hi@@WistrelChianti, without hardware floating point it is better to do it in fixed point math.
We had to do this with a bit of navigation equipment on an aircraft. we could not trust the C compiler to get it right every time as you have no control how it complies and builds the code. if you write your own fixed point routines it is easier to test and document.
Interesting!
I am constructing long string with int please help
Thanks!
Bless you!!
Hi brother .
i need some help how could I contact you?
I've been using assembly for arduino. Would it be worth my time to learn C++?
If you are using assembly you aren't using Arduino. And yes, learning C is worth the time. C is useful for many microcontroller families and on modern ones (modern meaning the last one or two decades) there's no point for using assembly at all (if for some reason you need assembly for a critically timed sequence you can inline it in C).
but how about making a video on atmel assembly for the rest of us? I can't think of a reason to go that low level for anything I have in mind personally. But if you have any nice ideas it would make a cool video or series.
@@WistrelChianti
There are some operations in an AVR that need to happen within a defined number of clock cycles of each other.
Or maybe you want to create a pulse of very defined width, if you are bitbanging some serial protocol for example.
Or you have some external device that has a certain setup time for some inputs before/outputs after you change some other pin.
Or one part of the machine code that the C compiler creates is just not fast enough (if that happens all the time you should question your programming skills/hardware choice though).
There are quite a few cases where knowing assembler is useful or necessary. But there is usually no need to write all the program in it.
a trap that can be a real time waster is that things like what is seen as decimal point by functions like atof() is determined by the c "locale"
That's interesting... so I'd always thought a decimal point was universally like: 42.2 What's the "locale" based alternative? Surely not: 42,2 ?
it surely is 42,2 ;)
I'd click "like", but really I want to click "ewww!"
hi my brother nice ok
I thought your youtube channel was dead?
This is really helpful. Working very well with Serial ports.
One problem I'm facing is when I'm using the SoftwareSerial port! I'm using a GSM module to parse some text from an SMS I'll send. But not working here! :(
Here's the screenshot of the code portion and the serial output! prnt.sc/wfwv2q
@#Kevin_Darrah or anyone here can help, please?
Thank you, Informative, great for a hobbyist like me, Lesson plans r awesome, Bless u 4 putting this info on RUclips!