title: How I can cause a program in C to print only one statement once it encounters a specific condition?
body: <p>I have been trying to write a C program where the user inputs a command-line argument and the program checks if it is all number digits or not. If that is true, the program simply reprints what the user put in. If that is false and there is at least one non-number mixed in, the program just prints the word &quot;bad&quot; once.</p>
  <p>What I have come up so far consists of the program checking each character of the input individually. However, what ends up happening once I put in a mixture of numbers and letters in is that the program would still print the numbers, and then once it gets to printing a letter, it prints the word &quot;bad&quot;.</p>
  <p>Here's an example:</p>
  <ul>
  <li>I put <code>./program 100x</code> into the terminal</li>
  </ul>
  <p>=&gt; Expected result: bad</p>
  <p>=&gt; Actual result: 100bad</p>
  <p>Here's the code:</p>
  <pre><code>#include &lt;cs50.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main (int argc, string argv[])
  {
      for(int i = 0; i &lt; strlen(argv[1]); i++) {
          if (isdigit(argv[1][i]) != 0) {
              printf(&quot;%c&quot;, argv[1][i]);
              return 0;
          } else {
              printf(&quot;bad&quot;);
              return 1;
          }
      }
  }
  </code></pre>