Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unlike the numeric conversion specifiers and <code>%s</code>, the <code>%c</code> conversion specifier does not skip blanks. Thus, given your example inputs, the <code>%*c</code> is reading the blank before the operator. You could sensibly use:</p> <pre><code>while (sscanf(matrix[i][c] + offset, " %c%d %c %c%d", &amp;col1, &amp;row1, &amp;op, &amp;col2, &amp;row2) == 5) ...data is OK... </code></pre> <p>Since you're using an offset and were capturing where the scan ended, you would use:</p> <pre><code>while (sscanf(matrix[i][c] + offset, " %c%d %c %c%d%n", &amp;col1, &amp;row1, &amp;op, &amp;col2, &amp;row2, &amp;readCharCount) == 5) ...data is OK... </code></pre> <p>Note that the <code>%n</code> conversion specifier is not counted, so the test remains against 5, not 6.</p> <p>Also note the careful placement of spaces in the format string. They're necessary and flexible (that would handle <code>A1+B2</code> OK, as well as <code>A1 + B2</code>). If you are going to allow bigger spreadsheets, you might prefer to specify:</p> <pre><code>while (sscanf(matrix[i][c] + offset, " %4[a-zA-Z]%d %c %4[a-zA-Z]%d%n", col1, &amp;row1, &amp;op, col2, &amp;row2, &amp;readCharCount) == 5) ...data is OK... </code></pre> <p>where the type of <code>col1</code> and <code>col2</code> changes from a single to <code>char col1[5]; char col2[5];</code> (which is why the <code>&amp;</code> was dropped, too). The scan sets allow inputs like <code>aAa1 + BbB2</code> to be recognized. Because of the <code>%d</code> notation, spaces are allowed between the letter or letters and the number (so the code would allow <code>aaa 999 + bbb 888</code>. Avoiding that is hard; I think you'd need to process the data with two scansets:</p> <pre><code>while (sscanf(matrix[i][c] + offset, " %4[a-zA-Z]%5[0-9] %c %4[a-zA-Z]%5[0-9]%n", col1, row1, &amp;op, col2, row2, &amp;readCharCount) == 5) ...data is OK... </code></pre> <p>where the types are now <code>char row1[6]; char row2[6];</code> and the ampersands have been dropped again. You can then confidently convert <code>row1</code> and <code>row2</code> into numbers.</p> <p>See also: <a href="https://stackoverflow.com/questions/7651397/calc-cell-convertor-in-c">Calc cell convertor in C</a> for code to convert column numbers into the corresponding alphabetic codes.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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