String overlapping when a struct : <p>I write a code to enter student information as follows. The problem occurs when the student ID append Lastname.I know that the error lies in entering id and Lastname but I can not understand and fix it</p>

<pre><code>#include "stdio.h"
#include "string.h"
typedef struct Fullname_s{
    char Lastname[20];
    char Fistname[10];
}Fullname;
typedef struct Birthday_s{
    int Day,Month,Year;
}Birthday;
typedef struct Mark_s{
    float mark[10];
}Mark;
typedef struct SV{
    char   ID[8];
    Fullname F_name;
    Birthday B_day;
    char   Sex[5];
    Mark _Mark;
}sv;
sv s[100];
void inputsv(sv s[],int *n); 
void printinfo(int i);
void output(sv s[],int n);
int main(){
    int n;
    inputsv(s,&amp;n);
    output(s,n);
}

void inputsv(sv s[],int *n){
    printf("--------Enter Students information--------\n");
    printf("Enter number of students \n");
    scanf("%d",n);
    int i=0;
    while(i&lt;*n){
        int x;
        printf("-------------------------Student %d-------------------------- \n",i+1);
        printf("ID Student   : ");
        fflush(stdin);
        scanf("%s",&amp;s[i].ID);
        gets();
        printf(" Lastname    : ");
        fgets(s[i].F_name.Lastname,20,stdin);
        printf(" Fistname    : ");
        gets(s[i].F_name.Fistname);       
        do{
            puts("Enter 0 :MALE");
            puts("Enter 1 :FEMALE");
            scanf("%d",&amp;x);
            if(x==0)
                strcpy(s[i].Sex,"MALE");
            else
                strcpy(s[i].Sex,"FEMALE");
        }while(x!=0&amp;&amp;x!=1);
        printf(" Birthday    : ");
        scanf("%d%d%d",&amp;s[i].B_day.Day,&amp;s[i].B_day.Month,&amp;s[i].B_day.Year);
        for(int j=0;j&lt;10;j++){
        printf(" Mark %2d:",j+1);
        scanf("%f",&amp;s[i]._Mark.mark[j]);
        }
        i++;
        gets();
    }
}

void output(sv s[],int n){
    printf("STUDENTS INFORMATION \n");
    for(int i=0;i&lt;n;i++){
        printf("--------------------\n");
        printf("  STUDENT %2d\n",i+1);
        printinfo(i);
        printf("-------------\n");
        }
    printf("------------------------\n");
} 

void printinfo(int i){
    printf(" ID STUDENT  :%s\n",s[i].ID);
    printf(" FULLNAME    :%s %s     \n",s[i].F_name.Lastname,s[i].F_name.Fistname);
    printf(" BIRTHDAY    :%2d-%2d-%4d \n",s[i].B_day.Day,s[i].B_day.Month,s[i].B_day.Year);
    printf(" SEX         :%s\n",s[i].Sex);
    for(int j=0;j&lt;10;j++){
        printf(" MARK    %2d  : %0.2f \n",j+1,s[i]._Mark.mark[j]);
    }
} 
</code></pre>

<p>Error as in the picture.Thanks all
<a href="https://i.stack.imgur.com/THxZP.jpg" rel="nofollow noreferrer">enter image description here</a></p>
