+ 2
How to print Nth word of a C char array?
How do i print the Nth word in a character array. For example. char mynames[15] = "David Holmes"; How do i print the "David" only or the "Holmes" only. If it was Python, i would: mynames = "David Holmes" tolist = mynames.split() print (tolist[0]) But since in C a string is already an array right, so i figured there is need to convert it to a array again đ
2 Answers
+ 2
Read this small short article about strtok in c (used for splitting a string)
https://www.google.com/amp/s/www.geeksforgeeks.org/how-to-split-a-string-in-cc-JUMP_LINK__&&__python__&&__JUMP_LINK-and-java/amp/
+ 1
you can use strtok() to split in c.
it takes a string and a delimiter.
delimiter in this case is " " space.
https://code.sololearn.com/cSm9Y3tbQEOa/?ref=app
in the example I printed each word on a new line, you can instead append each word to an array and print them like in your python example.