<p>When multiple <code>scanf()</code> statements are encountered in the code, then, except the first <code>scanf()</code> statement, all others are skipped, that is, there is no prompt for input for those <code>scanf()</code> statements when the code is run.</p>

<p>I have a tried a few suggestions. For eg, use of <code>flushall()</code> was suggested on some site, but that gives a compilation error. </p>

<p>Any help greatly appreciated.</p>

<p>[The code was added as <a href="https://stackoverflow.com/a/2787189/256431">an answer</a>.]</p>

[{'answer_id': 80626, 'author': 'paxdiablo', 'author_id': 14860, 'author_profile': 'https://Stackoverflow.com/users/14860', 'pm_score': 0, 'selected': False, 'text': "<p>I've always thought scanf() was dangerous as it can leave your input streams in an indeterminate state.</p>\n\n<p>I prefer to use other (safer) commands to bring in a string (fgets and such) then use sscanf to process it. Then you can always back up to the start of the string and restart.</p>\n"}, {'answer_id': 80644, 'author': 'Yuval F', 'author_id': 1702, 'author_profile': 'https://Stackoverflow.com/users/1702', 'pm_score': 0, 'selected': False, 'text': '<p>This sounds like some conversion issue. It may be that a %s conversion never ends or   you specify a character which is never input or something like this. I suggest the following:\na. Try something like:\n    int a=0;\n    int b=0;\n    scanf("%d", &amp;a);\n    scanf("%d", &amp;b);\n    printf("a=%d, b=%d\\n", a, b);\nIf this works, try augmenting the conversions, to see which one causes the problem.</p>\n'}, {'answer_id': 80752, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Check the return value of scanf()! </p>\n\n<p>From the man page:\n"scanf returns the number of input items assigned, which can be  fewer  than  provided  for,  or even zero, in the event of a matching failure.  Zero indicates that, while there was input available, no conversions were assigned;  typically  this  is  due  to  an invalid input character, such as an alphabetic character for a ‘%d’ conversion.  The value EOF is returned if an input failure occurs before any conversion such  as  an  end-of-file occurs.  If  an error or end-of-file occurs after conversion has begun, the number of conversions which were successfully completed is returned."</p>\n'}, {'answer_id': 93896, 'author': 'Martin York', 'author_id': 14065, 'author_profile': 'https://Stackoverflow.com/users/14065', 'pm_score': 2, 'selected': False, 'text': '<p>An example of the code <b>and</b> input would definitely improve our ability to help you with your specific problem as there are a lot of potential situations that can cause the problem.</p>\n\n<p>Example (I can think of quickly):</p>\n\n<ul>\n<li>The format string does not match the next character on the input stream. The scanf is thus not reading anything.</li>\n<li>The stdin input buffer is only flushed when full or return is encountered.<br></li>\n<li>The input from 1 line of typing may be used by multiple scanf statements. Subsequent scanf statements pick up where the last on left off. Thus the program does not stop for user input.</li>\n<li>The %s behaves differently on scanf and printf<br>\nprintf it prints a whole string.<br>\nscanf it read <b>ONE</b> space separated word</li>\n</ul>\n'}, {'answer_id': 2787189, 'author': 'Michał', 'author_id': 335226, 'author_profile': 'https://Stackoverflow.com/users/335226', 'pm_score': 0, 'selected': False, 'text': '<p>The Code simple, as it is:</p>\n\n<pre><code>#include &lt;stdio.h&gt;\nint main()\n{\nlong int z,s,n,i,j,m,x;\nscanf("%ld ",&amp;z);\nfor(i=0; i&lt;z; i++)\n  {\n  scanf("%ld",&amp;s); n=0;\n  for (j=0; j&lt;s; j++) { scanf("%ld",&amp;m); n+=m; }\n  x=n+s-1;\n  printf("%ld\\n",n);\n  }\nreturn 0;\n}\n</code></pre>\n\n<p>Compilation:</p>\n\n<pre><code>D:\\edycja&gt;gcc WSEGA.c -o WSEGA.exe -Wall\n\nD:\\edycja&gt;WSEGA.exe\n\nD:\\edycja&gt; [Where was the program!?]\n</code></pre>\n'}, {'answer_id': 7421650, 'author': 'Ashu', 'author_id': 939871, 'author_profile': 'https://Stackoverflow.com/users/939871', 'pm_score': 0, 'selected': False, 'text': '<p>always use ""fflush(stdin);"" before any "scanf();" statement because unless and until u don\'t clear the standard input stream scanf statement will read the already present value in std i/p.</p>\n'}]
['https://Stackoverflow.com/questions/80601', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']