Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'll pick on one loop, and leave it to you to rethink your implementation. Specifically this:</p> <pre><code>for(i = 0; isdigit(hexd[i]); i++) n = (16 * i) + (hexd[i] - '0'); </code></pre> <p>doesn't do what you probably think it does...</p> <ul> <li>It only processes the first span of characters where <code>isdigit()</code> is TRUE.</li> <li>It stops on the first character where <code>isdigit()</code> is FALSE.</li> <li>It doesn't run past the end because <code>isdigit('\0')</code> is known to be FALSE. I'm concerned that might be accidentally correct, though.</li> <li>It does correctly convert a hex number that can be expressed solely with digits 0-9.</li> </ul> <p>Things to think about for the whole program:</p> <ul> <li>Generally, prefer to not modify input strings unless the modification is a valuable side effect. In your example code, you are forcing the string to lower case in-place. Modifying the input string in-place means that a user writing <code>htoi("1234")</code> is invoking <em>undefined behavior</em>. You really <em>don't</em> want to do that.</li> <li>Only one of the loops over digits is going to process a non-zero number of digits.</li> <li>What happens if I send <code>0123456789ABCDEF0123456789ABCDEF</code> to <code>stdin</code>?</li> <li>What do you expect to get for <code>80000000</code>? What did you get? Are you surprised?</li> <li>Personally, I wouldn't use <code>NL</code> for <code>'\n'</code>. C usage pretty much expects to see <code>\n</code> in a lot of contexts where the macro is not convenient, so it is better to just get used to it now...</li> </ul>
    singulars
    1. This table or related slice is empty.
    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. 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