Hi,
I am trying to validate against gender in my code.
The function below accepts student details, part of its function is to verify that the correct lettter is enterd for gender 'm' or 'f'
It llooks like the program does not understand input as it treats all character inputs the same.any characters causes the function to abort.
You help will be apprecaited
I am trying to validate against gender in my code.
The function below accepts student details, part of its function is to verify that the correct lettter is enterd for gender 'm' or 'f'
It llooks like the program does not understand input as it treats all character inputs the same.any characters causes the function to abort.
You help will be apprecaited
Code:
getstudent_detail()
{
do{
fscanf(sfile,"%i %[^/]%*c %[^/]%*c %c %d%*c %s", &ID, Course, Name, &Gender, &Age, Enrollment_Date);
}while (!feof(sfile));
ID += 1;
}
printf("Course ID: ");
scanf(" %s", &Course);
printf("Student ID: %04i", ID);
printf("\nName: ");
fflush(stdin);
gets(Name);
printf("Gender: ");
scanf(" %c", &Gender);
if ( getchar()!='m'||getchar()!='f')
printf(" Please enter 'm' for Male or 'f' for Female :");
return(0);
printf("Age: ");
scanf("%d", &Age);
printf("Enrollment_Date in DD-MM-YY format: ");
scanf("%s", &Enrollment_Date);
printf("\nRecord saved!");
sleep(3);
fprintf(sfile,"%i %s/ %s/ %c %d %s\n", ID, Course, Name, Gender, Age,Enrollment_Date);
fclose(sfile);
}
Comment