Splitting strings in C can be quite confusing, especially if you're not used to other string.h functions. Here's a straightforward explanation of how you can do it.
Пікірлер: 197
@kkvaruas57595 жыл бұрын
trust me this is the best explanation on youtube about strtok
@piyushsaxena62434 жыл бұрын
Totally agree
@vedantgolash60843 жыл бұрын
agree
@user-rn7xi4vc3c3 жыл бұрын
I absolutely agree. I've been bashing my head against this for over an hour and I can finally get back to coding!
@CSERISHINANDHA3 жыл бұрын
@@user-rn7xi4vc3c exactly
@turnerbrentley35042 жыл бұрын
Sorry to be off topic but does anybody know of a trick to get back into an instagram account? I somehow lost the account password. I would love any assistance you can offer me.
@DeveloperDesmond4 жыл бұрын
This is such a good tutorial. It's all content no filler, but you still spend so much explaining all the details and nuances, which is key.
@JurGon123 жыл бұрын
I'm doing my C programming module at uni atm, and you are like a bible to me. Thanks for helping actually understanding C!
@DanielDybing3 жыл бұрын
Great video! I love how you explain things in a very easy and straight-forward way. It's just pure content!
@bushraw662 жыл бұрын
this video is so smooth and easily understandable.THANKYOU
@ignaciofernandez34239 ай бұрын
thanks, I´ve seen a couple of videos trying to understand strtok and you are the only one who explained it simple and to the point enough for me to understand
@kashishsingh19314 жыл бұрын
Thank you, thank you, thank you. This is so good, the explanation. I don't have anything to say as everything has already been said.
@rrMaxwell10 ай бұрын
excellent explanation. you taught the thing that i was reading on geeks for geeks for an hour in such a short itme
@caitlingibbons22463 жыл бұрын
Simply excellent. I was initially confused by the nuances of strtok, but this video was quite elucidating.
@tacotalks36973 жыл бұрын
I love you so much. You're the greatest C programmer and teacher the world has ever seen. You've saved me so much stress.
@supersmiley29544 жыл бұрын
Thanks buddy for saving my life at university 😅👍
@tcszebra23362 жыл бұрын
After subscribing this channel, i am in love with c coding.
@lost-in-my-maze80245 жыл бұрын
your explanation is awesome keep it up !!
@saravananjagadeeesan5933 жыл бұрын
Thanks a lot !!
@CSERISHINANDHA3 жыл бұрын
@@saravananjagadeeesan593 you're the admin of this channel?
@bschena3 жыл бұрын
Thank you! this is a GREAT explanation of what's going on with strtok! I found some example code but couldn't figure out what the heck it was doing. Powerful function to know! Thanks!
@atasharichmolina62143 жыл бұрын
pls do more of this (functions, tokens, problems in C/C++ and more) it helped me to become aware bcs seriously,, C/C++ have several functions and I badly needed someone who can explain it to me thoroughly bcs we are in an online setting of classes, so basically, self-study is my thing now. appreciate u dude!!
@juansuarezburgos5727 Жыл бұрын
Love your videos. Getting me through cs 50 at Dartmouth rn
@chelilack2 жыл бұрын
I have chocked when saw russian subtitles.Thanks for this
@dmacdougall61835 ай бұрын
Very good thanks for explaining all the details. I think this also helped me digest some of the other stuff i didnt quite get yet
@carracingsongs4 жыл бұрын
Juts what I was looking for. Thank you!
@dustonspear46184 жыл бұрын
Excellent tutorial. This video helped me very much. Thank you!
@Mikeriker Жыл бұрын
You expalained it very clearly. Thanks for this! Nice recap in the end haha
@toaastr84093 жыл бұрын
This man is one of the most important men in the world. I believe that.
@thebeesknees74675 жыл бұрын
This helped me a lot. Thank you! :D
@panagiotiskakalis73603 жыл бұрын
Love it!! This will help me for an important program assignment for my uni!
@yorgunkaptaan3 жыл бұрын
Thanks a lot, man. This explanation is really helpful.
@encore40863 жыл бұрын
Thank youuu, the best explanation about strtok.
@steveworks34094 жыл бұрын
Careful, he 's a hero.. Best video about strtok.
@joelmanning2493 жыл бұрын
Damn fine explanation. strtok has been bugging me for ages :D
@lucamartins72163 жыл бұрын
the best explanation on yt for sure
@atasharichmolina62143 жыл бұрын
best explanation!!!!!!! keep going Mr. :))) you helped me a lot
@Mr.AIFella3 жыл бұрын
Thank you for the video. It helps me with my H.W.
@swimmerbc3 жыл бұрын
Legendary dude, thanks for the explanation!
@supertonyxd4 жыл бұрын
Nice explanation! Thank you so much!
@sandhyag95683 жыл бұрын
Awesome Explanation....Best teacher you are
@ankitjha3724 жыл бұрын
Best go through explanation!!!
@rubix_x_code Жыл бұрын
love u bro !! Great explanation !!
@Karthik-kt242 жыл бұрын
very cool explanation!! explained everything very welll
@VasilijeVrbicАй бұрын
Great explanation. Cheers!
@marioauditore5712 жыл бұрын
this video / explaination really helped me out. End was the best tho " 'C' you next time". :D
@MissGamesKuma Жыл бұрын
Can I just say that your videos are so incredibly helpful!! I have found many videos on KZfaq helpful but this is the channel that I have come back to the most. Super friendly and easy to follow and understand. Plus so much content! Many thanks from a rookie coder!
@nenani18172 жыл бұрын
WOW!!! this is the best explnation ever!!
@hemersonallan11 ай бұрын
Awesome, Greetings from Brazil !!!
@4792102514 жыл бұрын
Thank you so much for this explanation
@sumitsingh-fm2nz3 жыл бұрын
thanks man it was really helpful!
@BiMathAx2 жыл бұрын
Just let me say to you a french thanks'you : Merci beaucoup, cette vidéo est complète et permet de comprendre strtok super simplement : MERCI
@TheLuckyyy133 жыл бұрын
Holy shit. I actually understood this better than i could imagine.
@Raja_IT_Trainer3 жыл бұрын
Great explanation... 👍👍
@swapnil8493 жыл бұрын
Thanks a lot....u can explain things so well :D
@guerreroestoicox4 жыл бұрын
thanks dude, I am suscribed already.
@innovativehacker37693 жыл бұрын
You are Genius mate!!
@legomeisterlp43753 жыл бұрын
Very very very good video 👍👍👍👍. Thanks!! 🤓😄
@robertwitt12764 жыл бұрын
This is super helpful thanks!
@crafty-jax74403 жыл бұрын
Great Video, I should be paying you my tuition.
@tyl61944 жыл бұрын
clear explanation. Thanks!
@Ganjena2k3 жыл бұрын
Great explanation!
@AlashAls4 жыл бұрын
Followed a lot of beginner C tutorials. No one talked about String token. Some books even skipped it.
@abdullahhussein69055 жыл бұрын
Thank you Dude.
@zyghom2 жыл бұрын
I am not sure if C is as simple as Linux or opposite but considering that in Linux/Unix "one program does one thing" is a mantra, and now seeing that C follows the same... Actually probably it is Linux/Unix that took from C. Irrespective: I like this approach. Yes, there are other functions or languages that do many things at once, but as long as they are built on such simple pieces... I like it ;-)
@enricofr70793 жыл бұрын
thanks, great explaination!
@rohanrn55154 жыл бұрын
The best explaination
@nithyasree26984 жыл бұрын
It's really helpful...tq
@annelin14164 жыл бұрын
nice explanationnnnnn!!!! thx
@maellm55864 жыл бұрын
thanks a lot! you save me !
@FernandoBasso3 жыл бұрын
Amazing and useful series for the amazing C Programming Language. Congrats are in order. 👍️ I would like to ask if it would be possible to make a video (or more than one, perhaps) about handling Unicode and UTF-8 strings (multi-byte strings) in C so we can handle non-ASCII-only, single byte characters as well.
@CodeVault3 жыл бұрын
Thanks! I will look into it.
@sukhendughosal68224 жыл бұрын
Nice explanation
@CSERISHINANDHA3 жыл бұрын
Thanks man!
@ishandorge53663 жыл бұрын
Well explained...
@piyushsaxena62434 жыл бұрын
Thanks a lot. Finally I understood strtok.
@gabrielsatwik51743 жыл бұрын
thank you!
@georger8443 жыл бұрын
Can you make a video about setting up a debugger like yours and how to use it? Also, your videos although short and very specific are very very useful,thanks.
@CodeVault3 жыл бұрын
I have this video for VSCode: code-vault.net/lesson/ublnbln8uf:1603733528013 I no longer use DevC++, but that should work out of the box without any configurations needed.
@lucaskalil9743 жыл бұрын
me ajudou muito em uma tarefa da facul muito obrigado :)
@ericgutierrez3474 жыл бұрын
THANK YOU!!!!
@rakshakumar45963 жыл бұрын
best video
@ishanfernando30643 жыл бұрын
Thank you
@aliciasamuel3123 жыл бұрын
Hello! Just wanted to say that your explanations are very detailed and helpful. Is it possible however to set a barrier token and retrieve the character in between it? Example, I would like to retrieve the number 5000 from the input [5000] where "[ ]" is the barrier token so I can assign that number to a variable later on? Sorry if this sounds confusing and thanks in advance for any help :)
@CodeVault3 жыл бұрын
Just use the "[]" string as delimiters for strtok. strtok will split at any of the characters found in that string: strtok(exampleString, "[]");
@aliciasamuel3123 жыл бұрын
@@CodeVault Ooh i see. Thank you so much :D
@flamendless3 жыл бұрын
Why is that when i see this guy, i think of modern day Linus Torvalds
@bharatnarayana84013 жыл бұрын
thank you so much for video saved my day {"sam","0004","SDE1","VLSI"} how to break this
@CodeVault3 жыл бұрын
You could probably just use: strtok(str, "\",\""); And ignore the first and the last piece you get (since those are just gonna have the { and } characters)
@Pwnedby Жыл бұрын
Thats a nice video. Im still learning c. Quick question at 7:24 could i use memory allocation to store each string so i can select the pieces by its index?
@CodeVault Жыл бұрын
Of course. Usually I suggest you simply make a statically allocated array of char pointers so you don't have to deal with allocating and deallocating elements of that array
@songchovui19052 жыл бұрын
Great, strtok(Null) is what i'm finding.
@lanaalqabaz80804 жыл бұрын
I personally prefer to use sscanf although in your example it would require creating a string variable for each word in the string. Might be a bit more work but it's simpler :D
@CodeVault4 жыл бұрын
Definitely. If you already know the exact number of words the sentence it's going to have *sscanf* is a much better option. Although *strtok* is mostly for parsing an array of any number of elements, that's where using *sscanf* gets a bit tricky. The example was supposed to show when you have to parse a string in which is encoded an *unknown* number of elements (in this case, words). In that case, one call to *sscanf* won't be enough. You could use *sscanf* in a while loop (with the format string *%[A-Za-z] %s*) and just keep getting the first word every iteration, which is fancier but requires more work than just using *strtok*. Thanks for the feedback!
@ahmedsheweita79883 жыл бұрын
Great Video
@CodeVault3 жыл бұрын
Yes, every time you call strtok, it will change piece.
@ahmedsheweita79883 жыл бұрын
Thank you for these amazing videos and for your fast response
@RaselAhmed-ix5ee3 жыл бұрын
one of the best tutorials can you help me with a problem its urgent please..reply ASAP
@CodeVault3 жыл бұрын
What's the problem?
@fabianzapata59774 жыл бұрын
Hey men i have i question, where is located the function youre using in this video to evaluate each code line youre selecting
@CodeVault4 жыл бұрын
I'm not sure which function you're talking about... You mean the debugger?
@tidakdiketahui51472 жыл бұрын
Very detailed video. But, i want to ask, how to store that each string into an array?
@CodeVault2 жыл бұрын
You could simply define 2D array of characters: char pieces[100][100]; int count = 0; And just copy each piece using strcpy, like so: strncpy(pieces[count++], piece, 99);
@tidakdiketahui51472 жыл бұрын
@@CodeVault Wow, superb. Finally it works. Thank you so much for your help. You've got a new subscriber 😁
@minhhuydo27013 жыл бұрын
Hi. Thanks for your video!!. I need you help just a litte bit. So my stuff works but It needs more improvement. As you said in 7:45, how can I seperate those spaces and add 0 instead? Or any function to add 0 in the string when there are 2 spaces ? Like: "a b"now become"a 0 0 b"
@CodeVault3 жыл бұрын
I think iterating over the string and manually checking each character (without using strtok) is the best option in this case
@minhhuydo27013 жыл бұрын
@@CodeVault ok let me see I can do something to add 0 in between ,,
@shakib_043 жыл бұрын
thanksss
@wowtheworldchannel3 жыл бұрын
Awesome. (y)
@jlow56953 жыл бұрын
thanks
@ronjeremy12325 жыл бұрын
given the position or index of a word in the string, could you remove it with strtok?
@CodeVault5 жыл бұрын
No, it won't work. I suggest using strcpy(str + wordIndex, str + wordIndex + wordSize); That will basically copy over the last part of your string (after the word you found) over that word, essentially deleting it.
@ronjeremy12325 жыл бұрын
@@CodeVault i used Strtok() to separate each word, then i iterated through them with a loop and copied the words onto a text file, and when i reached the index that was given, i just skipped copying that word
@CodeVault5 жыл бұрын
@@ronjeremy1232 Be careful with that. strtok takes a list of characters to split at, not a full string. So if you give it, let's say, "apple", it will split at the characters 'a', 'p', 'l' and 'e'. Not at the string "apple". That's why I think you cannot really use it for removing other words.
@ronjeremy12325 жыл бұрын
@@CodeVault but i was forced to use strtok and strcat specifically
@ronjeremy12325 жыл бұрын
And i separated them with strtok(str, " ")
@chamarasilva77002 жыл бұрын
So strtok function has unfreed memory when excited (Hence it can continue tokenizing). So how will this not be a memory leak issue?
@CodeVault2 жыл бұрын
We're not dynamically allocating anything in the video
@manasvinsharma17404 жыл бұрын
Which ide/compiler are you using?...
@CodeVault4 жыл бұрын
I'm using Dev C++ since it's lightweight and works out of the box. Here's the download link to it: sourceforge.net/projects/orwelldevcpp/
@alexbravo74673 жыл бұрын
thanks..
@sreyamathew3279 ай бұрын
Can you please tell me how to extract part of input string enclosed in " ". Like input sentence is: printf( "Result is") and I want to extract the part enclosed in double quotes. It's for lexical analyser using c
@CodeVault8 ай бұрын
Just use strtok() as shown in the video with the space character as delimiter
@LYJManchesterUnited4 жыл бұрын
Thanks i manged to get it to work but i wanna store each extracted word into an array but it doesn't work i put for example piece = exampleArray [i]; But it doesn't seem to work . Any help would be greatly appreciated thanks!
@CodeVault4 жыл бұрын
You will have to use strcpy to copy each piece to the array: strcpy(exampleArray[i], piece); I made a video regarding the difference between assigning and strcpy for strings. Maybe it helps: kzfaq.info/get/bejne/jLd4fpV2v8Cskmw.html
@pierrethehandsome25183 жыл бұрын
How would you group elements together? Like say if I wanted "Let's Break" "This String" "Into Pieces"
@CodeVault3 жыл бұрын
That is tricky to do with strtok. I suggest you iterate over your string and break it up that way if you need this custom grouping.
@sexer59534 жыл бұрын
but i have question, out of all the loops, why u chose while loop?
@CodeVault4 жыл бұрын
Good question! I could've used a for loop instead, and it would look something like this: for (char* piece = strtok(str, " "); piece != NULL; piece = strtok(NULL, " ")) { ... } It basically combined 3 lines of code into a really long single line. I just preferred the while loop since it is much easier to understand and explain. Feel free to use either one of them as long as it's easy to understand for you and for your team!
@nirajshewalkar32134 жыл бұрын
Thanks a lot,if you have uploaded any course on udemy or any other online programming site, please tell me.
@CodeVault4 жыл бұрын
There's a course on base convertions for number on Skillshare which you can check out here: www.skillshare.com/r/profile/Sergiu-Muresan/798146080 Otherwise, most content on Udemy is free and also on KZfaq
@cybrok32 жыл бұрын
And that's what i call USEFULL programming knowledge : \ lol
@nikirangdan__3 жыл бұрын
Sir what if I want to pass the value of piece, in this case the individual words, as a string argument to another function? How do I do that?
@CodeVault3 жыл бұрын
You simply pass it as a char* int fn(char* in) { ... } // then, after strtok fn(piece);
@nikirangdan__3 жыл бұрын
@@CodeVault Hello Sir, very thanks for the response. When I tried to copy your code, it prints the individual values right. However, printing the value is not what I am required to do. What I am required to do Sir is that I need to be able to build a linked list out of the individual pieces that I was able to extract using the strtok() method. So I made a push function that would append each "piece" from the given input string. When I tried to pass the piece and run the code, the output is not the same as the user's. :( I'm afraid the "piece" that was extracted is not of an integer/char type. Please help me sir. Also, may I email you the code for you to be able to fully grasp what I'm saying?
@CodeVault3 жыл бұрын
Yeah, then you might have to allocate space for it in the linked list's node and then call strcpy
@abdallahac62823 жыл бұрын
Is there a way to count how many spaces there are in the line?
@CodeVault3 жыл бұрын
Just iterate over the string's characters and compare each one with a space. There's no function that does this for you afaik.