Scanf is requesting two strings at once

c, printf, scanf, string

Solution

Remove the whitespace in scanf.

Change:

scanf("%s ",input);

to:

scanf("%s",input);

Due to the space, scanf keeps skipping whitespace characters until it reads something that's not a whitespace (after reading one string for `%s`).

Problem

In this segment of code the scanf is requesting twice and I am not sure what could be causing it to do so. ``` int t; for(t = 0;t<5;t++) { //scanf requests twice for some reason scanf("%s ",input); fprintf(fp,"%s ", input); printf("%d Word(s)\n", (t+2)); } ``` and the output is (words in quotes are entered in by the user) ``` "hello" "world" 1 Word(s) "how" 2 Word(s) "are" 3 Word(s) "you" 4 Word(s) "lostword" 5 Word(s) ``` And ``` "hello world how are you " ``` would be given back to me and saved into the file.

Original source