Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>scanf</code> works as documented. Also, there is nothing wrong with <code>scanf</code> so long as its function is understood.</p> <p>I created a copy of your code and distilled it to highlight what you want to do. You will need to fill-in the rest yourself.</p> <p>In this code you need to enter a digit and press enter. Then enter a string and press enter, etc. Note. the <code>fflush(stdout)</code> statement is part of the standard C implementation per K&amp;R. The <code>fflush</code> forces the contents of the buffer out to the console. This flushing makes for a reasonable user/computer dialog.</p> <pre><code>#include &lt;stdio.h&gt; main() { char string[100]; int helper; printf("Welk type? (Taak:1, Examen:2, Voordracht:3)\n"); fflush(stdout); scanf("%d",&amp;helper); //select an itemtype if (helper &lt; 1 || helper &gt; 3) { printf("wrong value, please try again"); return 0; } printf("Vul een naam in:\n"); fflush(stdout); scanf("%s", &amp;string[0]); printf("\n%s\n", string); printf("Vul een vaknaam in: \n"); fflush(stdout); scanf("%s", &amp;string[0]); printf("\n%s\n", string); printf("Vul een starttijd in:\n"); fflush(stdout); scanf("%s", &amp;string[0]); printf("\n%s\n", string); printf("Vul een eindtijd in: \n"); fflush(stdout); scanf("%s", &amp;string[0]); printf("\n%s\n", string); } </code></pre> <p>This code ran on Eclipse with a Microsoft C Compiler.</p> <p>Also, let me emphasize that if you enter: 1 AAA BBB CCC DDD and press enter then <code>scanf</code> will get executed five times. In this example, the code would run to completion!</p> <p>So you need to trace your code logic (in this case a straight line) to see how the scanfs are invoked based on what data is entered.</p> <p>Hope this helps. Please ask if more questions.</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