Im folgenden c-Code funktioniert scanf nicht. Wenn das Programm ausgeführt wird, führt es bis zur zweiten Druckzeile aus und überspringt das scanf ("% c", & Geschlecht); und führe direkt next printf() aus. Warum passiert das? Ich führe diesen Code auf verschiedenen c-Compiler, aber die Ausgabe ist identisch.Laufzeitfehler von Scanf();
#include<stdio.h>
void main()
{
char mar,sex;
int age,flag=0;
printf("Married [Y/N]:");
scanf("%c",&mar);
printf("Sex [M/F] :");
scanf("%c",&sex); //**This not working**
printf("Age :"); //**execution directly jumped here**
scanf("%d",&age);
if(mar=='y')
flag=1;
else if(sex=='m'&& age>=30)
flag=1;
else if(sex=='f'&& age>=25)
flag=1;
else
{
}
if(flag)
{
printf("Congratulations!!!! You are Egligible..");
else
printf("Sorry... You are not egligible..");
getch();
}
// Ausgabe
Married [Y/N]:y
Sex [M/F] :Age :23
Congratulations!!!! You are Egligible..