Hey Guys,
Here is the full 2 functions code, Its running but its not quite right.
Perhaps you guys will see what im missing.
Thanks again
Code:
/*functions for adding a record... */
void add_new_student(void)
{
int key;
char record_id[40];
clrscr();
/* Add the name & ID to the database*/
printf("\n\n\t\t Enter New Name And Reg No\n\n");
printf("Enter First Name: ");
gets(students_database[index].fname);
fflush(stdin);
printf("Enter Last Name: ");
gets(students_database[index].sname);
fflush(stdin);
printf("Please enter an 4 letter Reg No eg: w123 \n");
fgets(record_id,sizeof(record_id),stdin);
while(check_reg(record_id)!=1)
{
printf("Please RE-Enter A Reg No In The Correct Format eg: w123 \n");
fgets(record_id,sizeof(record_id),stdin);
}
printf("Reg ID %s Is In The Correct Format Now checking for avaliability \n",record_id);
/*check reg is available*/
while(reg_available(record_id)==0);
{
printf("Please RE-Enter A Reg No\n");
fgets(record_id,sizeof(record_id),stdin);
}
/*The string has passed so Add the string to the structs records*/
strcpy(students_database[index].reg_no, record_id);
printf("\nThis Registration ID Was Added\n");
printf("\nPlease Enter The Credits \n");
scanf("%d",&students_database[index].credit);
fflush(stdin);
while(students_database[index].credit <10)
{
printf("Credits are between 10-15 please choose again!");
scanf("%d",&students_database[index].credit);
fflush(stdin);
}
while(students_database[index].credit >15)
{
printf("Credits are between 10-15 please choose again!");
scanf("%d",&students_database[index].credit);
fflush(stdin);
}
key = getchar();
/* Increment the array */
index++;
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/* Function to check the if the ID/string has been added already */
char reg_available(char*string1)
{
int loop=0;
while(loop < index)
{
if( strcmp(students_database[loop].reg_no,string1) == 0)
{
printf("RECORD FOUND");
return 0;
}
loop++;
}
if(loop == index)
{
printf("NOT FOUND\n");
}
return 1;
}
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/