This function should accept student details from the user and store them in a structure. I'm using a temp array to hold the reg number as I'm going to perform a validation test on it later.
Code:
void add_student(studentRecord student[],int i){
system("cls");
printf("\nEnter Registration number :");
gets(temp);
strcpy(student[i].regNumber,temp);
printf("\nEnter Surname :");
gets(student[i].surname);
printf("\nEnter Forename :");
gets(student[i].forename);
printf("\nEnter number of credits :");
scanf("%d",&student[i].credits);
printf("Press any key to continue.\n");
}
When I display the structure I have some strange output i.e.
*** Input***
reg No : 1234
Surname : smith
Forename: john
Credits : 12
*** Actual output ***
reg No: 1234smith
Surname: smith
forename: john
credits: 6684136
Can any one help? I cant see why the Surname is being appended onto the Reg No or why the Credits are being displayed as an address ( I think ??!!)
if its any help this is the function I'm using to display the structure, for testing:
Code:
void display(studentRecord student[],int i){
printf("\nReg %s\n",student[i].regNumber);
printf("\nsurname %s\n",student[i].surname);
printf("\nforename %s\n",student[i].forename);
printf("\ncredit %d\n",student[i].credits);
getch();
}