Get input with fscanf
<p>I am building a program that enables the user to enter a movie and prints out the information that the user entered.</p>

<p>I'm using a <code>struct</code> to define the variables of a movie. The problem is that when the user enter the first to <code>fscanf()</code> <strong>with a space</strong>. Example: "Miami Vice" all of the other <code>puts()</code> prints after each other. The <code>stdin</code> do not work after. And I dont know why this is happening.</p>

<p>I've been reading about gets() and it has security issues so I should instead using fgets() or fscanf() for this. But I can't figure out what the problem is here.</p>

<p><strong>main.c</strong></p>

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

int main()
{
    struct movie m;

    puts("What was the title of the movie you saw?");
    fscanf(stdin, "%s", m.title);
    puts("What was the relase year?");
    fscanf(stdin, "%d", &amp;m.year);
    puts("How would you rate the movie? (1-10)");
    fscanf(stdin, "%d", &amp;m.rate);

    printf("You saw the movie %s which was released %d and you rated it a %d", m.title, m.year, m.rate);

    return 0;
}
</code></pre>

<p><strong>main.h</strong></p>

<pre><code>struct movie {
    char title[40];
    int rate;
    int year;
};
</code></pre>