You can't do what you want with scanf() alone.
What you'll need to do is read the string using fgets(), and then interpret it to extract strings you want. Logically, if you extract strings you want, and do nothing with any others the user might type in, they are effectively discarded.
It is generally not a good idea to loop on feof() either. There are various FAQ's around that explain why.
Rough code follows (note: it is written to illustrate the idea, not intended as perfection in coding);
Code:
#include the headers needed
int main()
{
while (1)
{
char str[20];
char str2[20];
char buffer[100];
fprintf(stdout, "Please enter a string and another string\n");
if (fgets(buffer, sizeof(buffer), stdin) == NULL) break; /* break on error or EOF */
int strings_read = sscanf(buffer, "%19s %19s", str, str2))
if (strings_read == 1)
{
/* Only 1 string input, nag user until we get the second */
do
{
strings_read = 0;
fprintf(stdout, "You only entered one string. Please input the second");
} while (fgets(buffer, sizeof(buffer), stdin) != NULL && (strings_read = sscanf(buffer, "%19s", str2)) != 1);
if (strings_read == 1) ++strings_read; /* since this is the second string */
}
if (strings_read == 2)
fprintf(stdout, "String 1 = %s , String 2 = %s\n",str,str2);
else /* an error occurred */
break;
}
}
}