Scanning a char array after scanning an integer in C
<p>I'm a newbie in programming. It is confusing me when I taking input of a char array after scanning an integer. It is not working properly.
The code is following:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

int main()
{
    char a[30];
    int x,y;
    scanf("%d",&amp;x);
    scanf("%[^\n]",a);
    scanf("%d",&amp;y);
    printf("%d\n%s\n%d",x,a,y);
    return 0;
}
</code></pre>

<p>Output is following:
<a href="https://i.stack.imgur.com/gZ99Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gZ99Y.png" alt="enter image description here"></a></p>