scanfleaves an input stream pointing to \n. In your case, it does not matter: each time it calls, it scanfwill move until it finds the next character without spaces. So give it 10 lines name, a, b, as the input will work as you expect.
But consider the following:
scanf("%d", &a);
fgets(str, 20, stdin);
fgets , , str \n, fgets .