Forums
New posts
Search forums
News
Security News
Technology News
Giveaways
Giveaways, Promotions and Contests
Discounts & Deals
Reviews
Users Reviews
Video Reviews
Support
Windows Malware Removal Help & Support
Inactive Support Threads
Mac Malware Removal Help & Support
Mobile Malware Removal Help & Support
Blog
Log in
Register
What's new
Search
Search titles only
By:
Search titles only
By:
Reply to thread
Menu
Install the app
Install
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Guides
Programming Guides & Questions
In C, how does strtok() break a string into tokens?
Message
<blockquote data-quote="quentisa" data-source="post: 1018962" data-attributes="member: 98424"><p>Please explain how the strtok() method works. According to the documentation, it splits the string into tokens. I can't figure out what it does based on the handbook.</p><p>[CODE]/* strtok example */</p><p>#include <stdio.h></p><p>#include <string.h></p><p></p><p>int main ()</p><p>{</p><p> char str[] ="- This, a sample string.";</p><p> char * pch;</p><p> printf ("Splitting string \"%s\" into tokens:\n",str);</p><p> pch = strtok (str," ,.-");</p><p> while (pch != NULL)</p><p> {</p><p> printf ("%s\n",pch);</p><p> pch = strtok (NULL, " ,.-");</p><p> }</p><p> return 0;</p><p>}[/CODE]</p><p>When the first while loop began, the contents of str were merely "this." I added watches on str and *pch to test its functionality. How did the following output appear on the screen?</p></blockquote><p></p>
[QUOTE="quentisa, post: 1018962, member: 98424"] Please explain how the strtok() method works. According to the documentation, it splits the string into tokens. I can't figure out what it does based on the handbook. [CODE]/* strtok example */ #include <stdio.h> #include <string.h> int main () { char str[] ="- This, a sample string."; char * pch; printf ("Splitting string \"%s\" into tokens:\n",str); pch = strtok (str," ,.-"); while (pch != NULL) { printf ("%s\n",pch); pch = strtok (NULL, " ,.-"); } return 0; }[/CODE] When the first while loop began, the contents of str were merely "this." I added watches on str and *pch to test its functionality. How did the following output appear on the screen? [/QUOTE]
Insert quotes…
Verification
Post reply
Top