Note that there are some explanatory texts on larger screens.

plurals
  1. POsimple way to delimit whitespace (once) in C when already using another delimiter
    primarykey
    data
    text
    <p>I have the following code</p> <pre><code>while (*ptr != ',') { int items_read = sscanf(ptr, "%91[^,]%n", field, &amp;n); printf("field = \"%s\"\n", field); field[0]='\0'; if (items_read == 1) ptr += n; /* advance the pointer by the number of characters read */ if ( *ptr != ',' ) { break; /* didn't find an expected delimiter, done? */ } ++ptr; /* skip the delimiter */ } </code></pre> <p>It reads through my string and creates a new array for each string it finds between the commas, however I have white space in the middle of the string. I have many strings that will be read in, and some of those have white space in more than one area (after that middle place) and I do not want that white space accounted for, just the first instances.</p> <p>I know I can put <code>|| ' '</code> on the <code>while line</code>, the <code>int line</code>, and/or the second <code>if line</code> but I haven't gotten to do what I need done.</p> <p>I've heard that using <code>strtok</code> isn't good, or at least there are better ways to do that. I do not know how to add additional 'flags' (like the commas in my code) for the code to by-pass. </p> <p>ex:<br> 3,875,837 file1.ext<br> 3,437,281 document two.txt</p> <p>I already have the beginnings doing what I want. </p> <pre><code>field1 = 3 field2 = 875 field3 = 837 </code></pre> <p>However I want the rest of the string on those 2 inputs to go into separate char arrays and print out as follows: </p> <pre><code>field4 = file1 field5 = ext </code></pre> <p>and </p> <pre><code>field4 = document field5 = two field6 = txt </code></pre> <p>Or, I'm thinking now, is there anyway I can extract the last iteration of that <code>char array field</code> in order to use another loop through the exact same code except replace the <code>,</code>s with <code>' '</code> spaces?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload