Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>%c</code> format string will always interpret the corresponding <code>printf</code> argument as a character. In this case, its probably not what you want.</p> <pre><code>printf("ASCII in BIN: %d\n", myChar); </code></pre> <p>will print out the ascii code point of <code>myChar</code> just by telling <code>printf</code> to treat it as a number.</p> <p>If you'd like to print out the string being returned by your <code>toBinary</code> function, you can do that with</p> <pre><code>printf("ASCII in BIN: %s\n", toBinary(myChar)); </code></pre> <p>There's a good reference of the various <code>%</code> codes and what they mean <a href="http://www.cplusplus.com/reference/cstdio/printf/" rel="nofollow">here</a>.</p> <hr> <p>However, it's also worth noting that your <code>toBinary</code> function probably doesn't do what you want. This loop condition:</p> <pre><code>for (int i = sizeof(binaryValue); i &gt;= 0; ++i) </code></pre> <p>will start at <code>sizeof(int)</code> and count up until it runs out of integers, then stop only because <code>INT_MAX + 1 == INT_MIN</code>. Because you're using <code>i</code> as an array index, this will almost certainly crash your program.</p> <p>You also need to make sure to terminate the string you're generating with a <code>'\0'</code>, as that is how subsequent calls to <code>printf</code> will recognize the string has ended.</p> <p>And, as noted in other answers, your <code>toBinary</code> implementation is also returning a pointer to a memory address that will get automatically deleted as soon as <code>toBinary</code> returns.</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