hi,
the following code generates the newline bug. Please help.


Code:
#include <stdio.h>


int main (int argc, const char * argv[])
{
    /*Village Administration Database
    fields 
    1. Name 
    2. Age 
    3. Sex
    */
    char name[1000][100];
    int age[1000];
    char sex;
    int gender;// boolean to verify gender
    int count = 0;
    
    // WELCOME
    
    fputs("WELCOME : Voters list Database\n",stdout);
    fputs("You can enter details of of 1000 voters(MAX)\n",stdout);
    
    for(;;)
    {
        
        printf("Please enter the details of Voter %d:",count+1);
    // NAME INPUT
    
    printf("Please enter the Name of the Voter :");
    fflush(stdin);
    fgets(name[count],100,stdin);
    
    
    // AGE INPUT
    
    fputs("Please enter the age of the Voter :", stdout);
    fflush(stdin);
    scanf(" %d",&age[count]);


    // SEX INPUT
    for(;;)
    {
        puts("Please enter Gender('M' for Male or 'F' for Female):");
        fflush(stdin);
        scanf(" %c",&sex);
        if(sex == 'm'|| sex=='f')
            break;
        {
            printf("ERROR!!!\nOnly 'M' or 'F' allowed\n ");
        }
    }
    gender = sex == 'm';
    
    //COUNT INCREMENT and CHECKING LIMIT
    count = count + 1;
    if(count == 999)
    {
        puts("YOU HAVE REACHED THE LIMIT OF ENTRIES");
        break;
    }
}
    
    // OUTPUT
    
    printf("NAME: %s",name[count]);
    printf("AGE: %d\n",age[count]);
    if(gender)
        printf("GENDER : MALE");
    else
        printf("GENDER : FEMALE");
    
    return 0;
}
BUG:

WELCOME : Voters list Database
You can enter details of of 1000 voters(MAX)
Please enter the details of Voter 1:Please enter the Name of the Voter :sandeep
Please enter the age of the Voter :29
Please enter Gender('M' for Male or 'F' for Female):
m
Please enter the details of Voter 2:Please enter the Name of the Voter :Please enter the age of the Voter :

---------------------------

On the second time around the loop, the program wouldn't stop for the name input.

please help... thanks in advance