Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wouldn't recommend using regexc for this problem, especially if you're new to C. You should be able to solve it using some of the basic standard library features. You seem to be on the right general track. You are reading in characters and determining what class they fit in. Since you know that a valid input consists of only numbers and the comma character, you can immediately terminate the program if you encounter anything that's not one of those two things. Here are a few tips that might help.</p> <p>If you're reading a character at a time, <code>getchar</code> might prove easier to use than <code>scanf</code>.</p> <p>Also, <code>isdigit</code> is a function. Instead of saying <code>if (c == isdigit)</code>, you want to say <code>if (isdigit(c))</code>.</p> <p>Your function <code>check_dig</code> is defined to return an <code>int</code>, but there is no <code>return</code> statement in the function. The function needs to be modified to return a value, and <code>main</code> needs to do something with this value. A general rule of thumb is that a function returns zero when it completes successfully, or it returns non-zero on an error. In your case, "success" could mean "the character was valid" and "error" could mean "the character was invalid". Making this change should let you eliminate the global variable <code>value</code>. You can also eliminate the global <code>c</code> if you pass the input to <code>check_dig</code> as a parameter (<code>c</code> would become a local variable inside <code>main()</code>).</p> <p>I recommend that you only use the <code>check_dig</code> function to <em>check</em> the digit, and that you remove the part that reads another character. You should make the decision whether or not to skip a character before calling <code>check_dig</code>. That way, you can separate your "read" code, your "skip" code, and your "check" code. This makes your program easier to read and debug.</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. 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