I'm trying to store characters in a struct variable's member which is an array, using getchar function. The problem is getchar() doesn't execute itself, although my algorithm seems to be right. If I try to use getchar at the beginning of the programm it works but when I'm using it inside the: if (input.pin==client[c].pin) at the very end of the programm, getchar doesn't execute itself. why?
typedef struct compte {
int pin;
char nom[10];
char prenom[10];
char ddn[11];
char adresse[40];
float solde;
}compte;
int main()
{
compte client[4]={
{3625,"Harris", "Donald","26/08/1987","62 rue Calmette", 35700.00 },
{4512,"Anderson","Pamela","21/01/1966","5 rue Charles le Chauve", 68400.66},
{9912,"Barry","Sylvia","03/04/1971","8 rue Courtine",130755.65},
{7164,"Cardec","Jonas","04/05/1941","51 rue de la vielle table",575441.41}
};
compte input;
int c=0;
int c2=0;
int L;
int i=0;
printf("BIENVENU A LA SOCIETE GENERALE");
printf("\nCode pin sur 4 chiffres: ");
scanf("%d", &input.pin);
while ( input.pin != client[c].pin )
{
c++;
if (c==4)
{
c=0;
c2++;
printf("\nCode pin introuvable.\nReessayez: ");
scanf("%d",&input.pin);
}
while (c2==2 && input.pin != client[c].pin )
{
c++;
if(c==4)
{
printf("\n\nCode pin introuvable. Reprenez votre carte.\n");
break;
}
}
}
if (input.pin==client[c].pin)
{
printf("\n\nEntrez votre nom, prenom, date de naissance et adresse.\n\n");
printf("NOM: ");
scanf("%s", input.nom);
printf("PRENOM: ");
scanf("%s", input.prenom);
printf("DATE DE NAISSANCE AU FORMAT 00/00/0000: ");
scanf("%s", input.ddn);
while( input.ddn[2] != '/' && input.ddn[5] != '/' )
{
printf("\nVotre date de naissance doit être au format 00/00/0000.");
printf("\nEntrez votre date de naissance au format 00/00/0000: ");
scanf("%s", input.ddn);
}
printf("ADRESSE: ");
while((L=getchar())!= '\n')
{
if (i<5)
{
input.adresse[i]=L;
i++;
}
}
input.adresse[i]='\0';
}
return 0;
}