Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First; indent your code correctly (on Linux you could use the <a href="http://www.gnu.org/software/indent/" rel="nofollow">GNU indent</a> utility, or <a href="http://astyle.sourceforge.net/" rel="nofollow">astyle</a>).</p> <p>Compile it with all warnings and debugging info (e.g. <code>gcc -Wall -g</code>). Learn how to use the debugger (<code>gdb</code>) to run it step by step.</p> <p>Then, your <code>scanf("%s", str);</code> is dangerous (should at least be <code>scanf("%99s", str);</code>, see <a href="http://man7.org/linux/man-pages/man3/scanf.3.html" rel="nofollow">scanf(3)</a>) ! You could get crashes or <a href="http://en.wikipedia.org/wiki/Undefined_behavior" rel="nofollow">undefined behavior</a> if the user enters a very long "word" of 200 characters (e.g. 200 times the digit <code>0</code>). Alos notice that <code>%s</code> reads up to a space or blank-like character. I believe it is good habit to zero a buffer before reading it. So replace your <code>scanf</code> with </p> <pre><code> memset (str, 0, sizeof(str)); fgets (str, sizeof(str), stdin); </code></pre> <p>At last, you are not flushing the <a href="http://en.wikipedia.org/wiki/Buffer_%28computer_science%29" rel="nofollow">buffered</a> <code>stdout</code> output (see <a href="http://man7.org/linux/man-pages/man3/stdio.3.html" rel="nofollow">stdio(3)</a>, <a href="http://man7.org/linux/man-pages/man3/setvbuf.3.html" rel="nofollow">setvbuf(3)</a>, <a href="http://man7.org/linux/man-pages/man3/fflush.3.html" rel="nofollow">fflush(3)</a>, etc...). Try perhaps</p> <pre><code>while(str[i]) printf("%d ",str[i++]); putchar('\n'); fflush(stdout); </code></pre> <p>The last call to <code>fflush</code> is useless here, but it is a good habit (or else end <em>every</em> <code>printf</code> format string with a newline <code>\n</code> since <em><code>stdout</code></em> is often but not always line-buffered!)</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. This table or related slice is empty.
    1. 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