I cant get this code to stop allowing overfollow on the inputs. at the moment it carries any char's over 7 on to the next line and messes it up.

is there a way i can stop this?

Code:

#include <stdio.h>
int main()
{
char a[10];
char b[10];
char out[20];
printf( "Please enter a Maximum of 7 whole numbers: " );
fgets( a, sizeof a, stdin );
printf( "Enter your last name: " );
fgets( b, sizeof b, stdin );
printf( "\nString 'a' %s \n", a);
printf( "\nString 'b' %s \n", b);
if (a[0] == b [0])
out[0] = a[0];
else {
out[0] = 45;
}
if (a[1] == b [1])
out[1] = a[1];
else {
out[1] = 45;
}
if (a[2] == b[2])
out[2] = a[2];
else {
out[2] = 45;
}
if (a[3] == b [3])
out[3] = a[3];
else {
out[3] = 45;
}
if (a[4] == b[4])
out[4] = a[4];
else {
out[4] = 45;
}
if (a[5] == b[5])
out[5] = a[5];
else {
out[5] = 45;
}
if (a[6] == b[6])
out[6] = a[6];
else {
out[6] = 45;
}
if (a[7] == b[7])
out[7] = a[7];
else {
out[7] = 45;
}
//out[8] ='\0';
printf( "\nThe intersection is %s \n", out);
getchar();
return 0;
}