{"id":64004,"date":"2022-04-30T09:01:58","date_gmt":"2022-04-30T09:01:58","guid":{"rendered":"https:\/\/www.cryptocabaret.com\/?p=64004"},"modified":"2022-04-30T09:01:58","modified_gmt":"2022-04-30T09:01:58","slug":"parsing-data-with-strtok-in-c","status":"publish","type":"post","link":"https:\/\/www.cryptocabaret.com\/?p=64004","title":{"rendered":"Parsing data with strtok in C"},"content":{"rendered":"<p><span class=\"field field--name-title field--type-string field--label-hidden\">Parsing data with strtok in C<\/span><br \/>\n<span class=\"field field--name-uid field--type-entity-reference field--label-hidden\"><a title=\"View user profile.\" href=\"https:\/\/opensource.com\/users\/jim-hall\" class=\"username\">Jim Hall<\/a><\/span><br \/>\n<span class=\"field field--name-created field--type-created field--label-hidden\">Sat, 04\/30\/2022 &#8211; 03:00<\/span><\/p>\n<div data-drupal-selector=\"rate-node-69986\" class=\"rate-widget-thumbs-up\" title=\"Register or Login to like.\">\n<div class=\"rate-thumbs-up-btn-up vote-pending\"><a href=\"https:\/\/opensource.com\/user\/register\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml\">Login<\/a> to like<\/div>\n<div class=\"rate-score\"><a href=\"https:\/\/opensource.com\/user\/register\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml\">Login<\/a> to like<\/div>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item\">\n<p>Some programs can just process an entire file at once, and other programs need to examine the file line-by-line. In the latter case, you likely need to parse data in each line. Fortunately, the C programming language has a standard C library function to do just that.<\/p>\n<p>The <strong>strtok<\/strong> function breaks up a line of data according to &#8220;delimiters&#8221; that divide each field. It provides a streamlined way to parse data from an input string.<\/p>\n<h2>Reading the first token<\/h2>\n<p>Suppose your program needs to read a data file, where each line is separated into different fields with a semicolon. For example, one line from the data file might look like this:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"c geshifilter-c\"><span class=\"nu0\">102<\/span><span class=\"sy0\">*<\/span><span class=\"nu0\">103<\/span><span class=\"sy0\">;<\/span>K1.2<span class=\"sy0\">;<\/span>K0.5<\/code><\/span><\/pre>\n<p>In this example, store that in a string variable. You might have read this string into memory using any number of methods. Here&#8217;s the line of code:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"c geshifilter-c\"><span class=\"kw4\">char<\/span> string<span class=\"br0\">[<\/span><span class=\"br0\">]<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">\"102*103;K1.2;K0.5\"<\/span><span class=\"sy0\">;<\/span><\/code><\/span><\/pre>\n<p>Once you have the line in a string, you can use <strong>strtok<\/strong> to pull out &#8220;tokens.&#8221; Each token is part of the string, up to the next delimiter. The basic call to <strong>strtok<\/strong> looks like this:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"c geshifilter-c\"><span class=\"co2\">#include <string.h><\/string.h><\/span><br><span class=\"kw4\">char<\/span> <span class=\"sy0\">*<\/span><a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/strtok.html\"><span class=\"kw3\">strtok<\/span><\/a><span class=\"br0\">(<\/span><span class=\"kw4\">char<\/span> <span class=\"sy0\">*<\/span>string<span class=\"sy0\">,<\/span> <span class=\"kw4\">const<\/span> <span class=\"kw4\">char<\/span> <span class=\"sy0\">*<\/span>delim<span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div><\/div><\/pre>\n<p>The first call to <strong>strtok<\/strong> reads the string, adds a null (<code>\u0000<\/code>) character at the first delimiter, then returns a pointer to the first token. If the string is already empty, <strong>strtok<\/strong> returns NULL.<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"c geshifilter-c\"><span class=\"co2\">#include <stdio.h><\/stdio.h><\/span><br><span class=\"co2\">#include <string.h><\/string.h><\/span><br><br><span class=\"kw4\">int<\/span><br>\nmain<span class=\"br0\">(<\/span><span class=\"br0\">)<\/span><br><span class=\"br0\">{<\/span><br>\n\u00a0 <span class=\"kw4\">char<\/span> string<span class=\"br0\">[<\/span><span class=\"br0\">]<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">\"102*103;K1.2;K0.5\"<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 <span class=\"kw4\">char<\/span> <span class=\"sy0\">*<\/span>token<span class=\"sy0\">;<\/span><br><br>\n\u00a0 token <span class=\"sy0\">=<\/span> <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/strtok.html\"><span class=\"kw3\">strtok<\/span><\/a><span class=\"br0\">(<\/span>string<span class=\"sy0\">,<\/span> <span class=\"st0\">\";\"<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br><br>\n\u00a0 <span class=\"kw1\">if<\/span> <span class=\"br0\">(<\/span>token <span class=\"sy0\">==<\/span> NULL<span class=\"br0\">)<\/span> <span class=\"br0\">{<\/span><br>\n\u00a0 \u00a0 <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/puts.html\"><span class=\"kw3\">puts<\/span><\/a><span class=\"br0\">(<\/span><span class=\"st0\">\"empty string!\"<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 \u00a0 <span class=\"kw1\">return<\/span> <span class=\"nu0\">1<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 <span class=\"br0\">}<\/span><br><br>\n\u00a0 <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/puts.html\"><span class=\"kw3\">puts<\/span><\/a><span class=\"br0\">(<\/span>token<span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br><br>\n\u00a0 <span class=\"kw1\">return<\/span> <span class=\"nu0\">0<\/span><span class=\"sy0\">;<\/span><br><span class=\"br0\">}<\/span><\/div><\/div><\/pre>\n<p>This sample program pulls off the first token in the string, prints it, and exits. If you compile this program and run it, you should see this output:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"c geshifilter-c\"><span class=\"nu0\">102<\/span><span class=\"sy0\">*<\/span><span class=\"nu0\">103<\/span><\/code><\/span><\/pre>\n<p>102*103 is the first part of the input string, up to the first semicolon. That&#8217;s the first token in the string.<\/p>\n<p>Note that calling <strong>strtok<\/strong> modifies the string you are examining. If you want the original string preserved, make a copy before using <strong>strtok<\/strong>.<\/p>\n<\/p>\n<div class=\"embedded-resource-list callout-float-right\">\n<div class=\"field field--name-title field--type-string field--label-hidden field__item\">Programming and development<\/div>\n<div class=\"field field--name-links field--type-link field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/developers.redhat.com\/?intcmp=7016000000127cYAAQ\">Red Hat Developers Blog<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/cheat-sheets?intcmp=7016000000127cYAAQ\">Programming cheat sheets<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/www.redhat.com\/en\/services\/training\/learning-subscription?intcmp=7016000000127cYAAQ\">Try for free: Red Hat Learning Subscription<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/bash-programming-guide?intcmp=7016000000127cYAAQ\">eBook: An introduction to programming with Bash<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/developers.redhat.com\/cheat-sheets\/bash-shell-cheat-sheet?intcmp=7016000000127cYAAQ\">Bash shell scripting cheat sheet<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/developers.redhat.com\/e-books\/modernizing-enterprise-java?intcmp=7016000000127cYAAQ\">eBook: Modernizing Enterprise Java<\/a><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<h2>Reading the rest of the string as tokens<\/h2>\n<p>Separating the rest of the string into tokens requires calling <strong>strtok<\/strong> multiple times until all tokens are read. After parsing the first token with <strong>strtok<\/strong>, any further calls to <strong>strtok<\/strong> must use NULL in place of the string variable. The NULL allows <strong>strtok<\/strong> to use an internal pointer to the next position in the string.<\/p>\n<p>Modify the sample program to read the rest of the string as tokens. Use a while loop to call <strong>strtok<\/strong> multiple times until you get NULL.<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"c geshifilter-c\"><span class=\"co2\">#include <stdio.h><\/stdio.h><\/span><br><span class=\"co2\">#include <string.h><\/string.h><\/span><br><br><span class=\"kw4\">int<\/span><br>\nmain<span class=\"br0\">(<\/span><span class=\"br0\">)<\/span><br><span class=\"br0\">{<\/span><br>\n\u00a0 <span class=\"kw4\">char<\/span> string<span class=\"br0\">[<\/span><span class=\"br0\">]<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">\"102*103;K1.2;K0.5\"<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 <span class=\"kw4\">char<\/span> <span class=\"sy0\">*<\/span>token<span class=\"sy0\">;<\/span><br><br>\n\u00a0 token <span class=\"sy0\">=<\/span> <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/strtok.html\"><span class=\"kw3\">strtok<\/span><\/a><span class=\"br0\">(<\/span>string<span class=\"sy0\">,<\/span> <span class=\"st0\">\";\"<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br><br>\n\u00a0 <span class=\"kw1\">if<\/span> <span class=\"br0\">(<\/span>token <span class=\"sy0\">==<\/span> NULL<span class=\"br0\">)<\/span> <span class=\"br0\">{<\/span><br>\n\u00a0 \u00a0 <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/puts.html\"><span class=\"kw3\">puts<\/span><\/a><span class=\"br0\">(<\/span><span class=\"st0\">\"empty string!\"<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 \u00a0 <span class=\"kw1\">return<\/span> <span class=\"nu0\">1<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 <span class=\"br0\">}<\/span><br><br>\n\u00a0 <span class=\"kw1\">while<\/span> <span class=\"br0\">(<\/span>token<span class=\"br0\">)<\/span> <span class=\"br0\">{<\/span><br>\n\u00a0 \u00a0 <span class=\"coMULTI\">\/* print the token *\/<\/span><br>\n\u00a0 \u00a0 <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/puts.html\"><span class=\"kw3\">puts<\/span><\/a><span class=\"br0\">(<\/span>token<span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br><br>\n\u00a0 \u00a0 <span class=\"coMULTI\">\/* parse the same string again *\/<\/span><br>\n\u00a0 \u00a0 token <span class=\"sy0\">=<\/span> <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/strtok.html\"><span class=\"kw3\">strtok<\/span><\/a><span class=\"br0\">(<\/span>NULL<span class=\"sy0\">,<\/span> <span class=\"st0\">\";\"<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 <span class=\"br0\">}<\/span><br><br>\n\u00a0 <span class=\"kw1\">return<\/span> <span class=\"nu0\">0<\/span><span class=\"sy0\">;<\/span><br><span class=\"br0\">}<\/span><\/div><\/div><\/pre>\n<p>By adding the while loop, you can parse the rest of the string, one token at a time. If you compile and run this sample program, you should see each token printed on a separate line, like this:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"c geshifilter-c\"><span class=\"nu0\">102<\/span><span class=\"sy0\">*<\/span><span class=\"nu0\">103<\/span><br>\nK1.2<br>\nK0.5<\/div><\/div><\/pre>\n<h2>Multiple delimiters in the input string<\/h2>\n<p>Using <strong>strtok<\/strong> provides a quick and easy way to break up a string into just the parts you&#8217;re looking for. You can use <strong>strtok<\/strong> to parse all kinds of data, from plain text files to complex data. However, be careful that multiple delimiters next to each other are the same as one delimiter.<\/p>\n<p>For example, if you were reading CSV data (comma-separated values, such as data from a spreadsheet), you might expect a list of four numbers to look like this:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"c geshifilter-c\"><span class=\"nu0\">1<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">2<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">3<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">4<\/span><\/code><\/span><\/pre>\n<p>But if the third &#8220;column&#8221; in the data was empty, the CSV might instead look like this:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"c geshifilter-c\"><span class=\"nu0\">1<\/span><span class=\"sy0\">,<\/span><span class=\"nu0\">2<\/span><span class=\"sy0\">,,<\/span><span class=\"nu0\">4<\/span><\/code><\/span><\/pre>\n<p>This is where you need to be careful with <strong>strtok<\/strong>. With <strong>strtok<\/strong>, multiple delimiters next to each other are the same as a single delimiter. You can see this by modifying the sample program to call <strong>strtok<\/strong> with a comma delimiter:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"c geshifilter-c\"><span class=\"co2\">#include <stdio.h><\/stdio.h><\/span><br><span class=\"co2\">#include <string.h><\/string.h><\/span><br><br><span class=\"kw4\">int<\/span><br>\nmain<span class=\"br0\">(<\/span><span class=\"br0\">)<\/span><br><span class=\"br0\">{<\/span><br>\n\u00a0 <span class=\"kw4\">char<\/span> string<span class=\"br0\">[<\/span><span class=\"br0\">]<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">\"1,2,,4\"<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 <span class=\"kw4\">char<\/span> <span class=\"sy0\">*<\/span>token<span class=\"sy0\">;<\/span><br><br>\n\u00a0 token <span class=\"sy0\">=<\/span> <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/strtok.html\"><span class=\"kw3\">strtok<\/span><\/a><span class=\"br0\">(<\/span>string<span class=\"sy0\">,<\/span> <span class=\"st0\">\",\"<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br><br>\n\u00a0 <span class=\"kw1\">if<\/span> <span class=\"br0\">(<\/span>token <span class=\"sy0\">==<\/span> NULL<span class=\"br0\">)<\/span> <span class=\"br0\">{<\/span><br>\n\u00a0 \u00a0 <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/puts.html\"><span class=\"kw3\">puts<\/span><\/a><span class=\"br0\">(<\/span><span class=\"st0\">\"empty string!\"<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 \u00a0 <span class=\"kw1\">return<\/span> <span class=\"nu0\">1<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 <span class=\"br0\">}<\/span><br><br>\n\u00a0 <span class=\"kw1\">while<\/span> <span class=\"br0\">(<\/span>token<span class=\"br0\">)<\/span> <span class=\"br0\">{<\/span><br>\n\u00a0 \u00a0 <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/puts.html\"><span class=\"kw3\">puts<\/span><\/a><span class=\"br0\">(<\/span>token<span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 \u00a0 token <span class=\"sy0\">=<\/span> <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/strtok.html\"><span class=\"kw3\">strtok<\/span><\/a><span class=\"br0\">(<\/span>NULL<span class=\"sy0\">,<\/span> <span class=\"st0\">\",\"<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 <span class=\"br0\">}<\/span><br><br>\n\u00a0 <span class=\"kw1\">return<\/span> <span class=\"nu0\">0<\/span><span class=\"sy0\">;<\/span><br><span class=\"br0\">}<\/span><\/div><\/div><\/pre>\n<p>If you compile and run this new program, you&#8217;ll see <strong>strtok<\/strong> interprets the <code>,,<\/code> as a single comma and parses the data as three numbers:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"c geshifilter-c\"><span class=\"nu0\">1<\/span><br><span class=\"nu0\">2<\/span><br><span class=\"nu0\">4<\/span><\/div><\/div><\/pre>\n<p>Knowing this limitation in <strong>strtok<\/strong> can save you hours of debugging.<\/p>\n<h2>Using multiple delimiters in strtok<\/h2>\n<p>You might wonder why the <strong>strtok<\/strong> function uses a string for the delimiter instead of a single character. That&#8217;s because <strong>strtok<\/strong> can look for different delimiters in the string. For example, a string of text might have spaces and tabs between each word. In this case, you would use each of those &#8220;whitespace&#8221; characters as delimiters:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"c geshifilter-c\"><span class=\"co2\">#include <stdio.h><\/stdio.h><\/span><br><span class=\"co2\">#include <string.h><\/string.h><\/span><br><br><span class=\"kw4\">int<\/span><br>\nmain<span class=\"br0\">(<\/span><span class=\"br0\">)<\/span><br><span class=\"br0\">{<\/span><br>\n\u00a0 <span class=\"kw4\">char<\/span> string<span class=\"br0\">[<\/span><span class=\"br0\">]<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">\" \u00a0hello <span class=\"es1\">t<\/span> world\"<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 <span class=\"kw4\">char<\/span> <span class=\"sy0\">*<\/span>token<span class=\"sy0\">;<\/span><br><br>\n\u00a0 token <span class=\"sy0\">=<\/span> <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/strtok.html\"><span class=\"kw3\">strtok<\/span><\/a><span class=\"br0\">(<\/span>string<span class=\"sy0\">,<\/span> <span class=\"st0\">\" <span class=\"es1\">t<\/span>\"<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br><br>\n\u00a0 <span class=\"kw1\">if<\/span> <span class=\"br0\">(<\/span>token <span class=\"sy0\">==<\/span> NULL<span class=\"br0\">)<\/span> <span class=\"br0\">{<\/span><br>\n\u00a0 \u00a0 <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/puts.html\"><span class=\"kw3\">puts<\/span><\/a><span class=\"br0\">(<\/span><span class=\"st0\">\"empty string\"<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 \u00a0 <span class=\"kw1\">return<\/span> <span class=\"nu0\">1<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 <span class=\"br0\">}<\/span><br><br>\n\u00a0 <span class=\"kw1\">while<\/span> <span class=\"br0\">(<\/span>token<span class=\"br0\">)<\/span> <span class=\"br0\">{<\/span><br>\n\u00a0 \u00a0 <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/puts.html\"><span class=\"kw3\">puts<\/span><\/a><span class=\"br0\">(<\/span>token<span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 \u00a0 token <span class=\"sy0\">=<\/span> <a href=\"http:\/\/www.opengroup.org\/onlinepubs\/009695399\/functions\/strtok.html\"><span class=\"kw3\">strtok<\/span><\/a><span class=\"br0\">(<\/span>NULL<span class=\"sy0\">,<\/span> <span class=\"st0\">\" <span class=\"es1\">t<\/span>\"<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><br>\n\u00a0 <span class=\"br0\">}<\/span><br><br>\n\u00a0 <span class=\"kw1\">return<\/span> <span class=\"nu0\">0<\/span><span class=\"sy0\">;<\/span><br><span class=\"br0\">}<\/span><\/div><\/div><\/pre>\n<p>Each call to <strong>strtok<\/strong> uses both a space and tab character as the delimiter string, allowing <strong>strtok<\/strong> to parse the line correctly into two tokens.<\/p>\n<h2>Wrap up<\/h2>\n<p>The <strong>strtok<\/strong> function is a handy way to read and interpret data from strings. Use it in your next project to simplify how you read data into your program.<\/p>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-field-article-subhead field--type-text-long field--label-hidden field__item\">\n<p>The strtok function is a handy way to read and interpret data from strings. Use it in your next project to simplify how you read data into your program.<\/p>\n<\/div>\n<div class=\"field field--name-field-lead-image field--type-entity-reference field--label-hidden field__item\">\n<article class=\"media media--type-image media--view-mode-caption\">\n<div class=\"field field--name-field-media-image field--type-image field--label-hidden field__item\">  <img decoding=\"async\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/04\/OSDC_women_computing_4.png\" width=\"520\" height=\"292\" alt=\"Woman sitting in front of her laptop\" title=\"Women in tech and computing\" loading=\"lazy\"><\/div>\n<div class=\"field field--name-field-caption field--type-text-long field--label-hidden caption field__item\"><span class=\"caption__byline\">Image by: <\/span><\/p>\n<p>kris kr\u00fcg<\/p>\n<\/div>\n<\/article>\n<\/div>\n<div class=\"field field--name-field-tags field--type-entity-reference field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/programming\" hreflang=\"en\">Programming<\/a><\/div>\n<\/p><\/div>\n<div class=\"hidden field field--name-field-listicle-title field--type-string field--label-hidden field__item\">What to read next<\/div>\n<div class=\"field field--name-field-default-license field--type-list-string field--label-hidden field__item\"><a rel=\"license\" href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/\"><br \/>\n        <img decoding=\"async\" alt=\"Creative Commons License\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/04\/cc-by-sa--45.png\" title=\"This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.\"><\/a>This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.<\/div>\n<section class=\"field field--name-field-comments field--type-comment field--label-hidden comment-wrapper\">\n<div class=\"comments__count\">\n<div class=\"login\"><a href=\"https:\/\/opensource.com\/user\/register?absolute=1\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml&amp;absolute=1\">Login<\/a> to post a comment.<\/div>\n<\/p><\/div>\n<\/section>\n<p class=\"wpematico_credit\"><small>Powered by <a href=\"http:\/\/www.wpematico.com\" target=\"_blank\" rel=\"noopener\">WPeMatico<\/a><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Parsing data with strtok in C Jim Hall Sat, 04\/30\/2022 &#8211; 03:00 Register or Login to like Register or Login to like Some programs can just process an entire file at once, and other programs need to examine the file line-by-line. In the latter case, you likely need to parse data in each line. Fortunately, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":64005,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[307],"tags":[],"class_list":["post-64004","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-open-source"],"_links":{"self":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/64004","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=64004"}],"version-history":[{"count":0,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/64004\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/media\/64005"}],"wp:attachment":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=64004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=64004"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=64004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}