Adak I need to sort it only by the month of the birthday, I do not know if i've done this right but here is the updated version.
Code:
#include<stdio.h>
struct sdate
{
int month;
int day;
int year;
};
struct sStudent
{
char last_name[30];
char first_name[30];
struct sdate birthday;
}Algebra[10];
void get_first_name(int j)
{
printf("First name ");
scanf("%s", Algebra[j].first_name);
}
void get_last_name(int j)
{
printf("Last name ");
scanf("%s", Algebra[j].last_name);
}
void get_date_of_birth(int j)
{
printf("Birthday ");
scanf("%i%i%i", &Algebra[j].birthday.day, &Algebra[j].birthday.month, &Algebra[j].birthday.year);
printf("\n");
}
int get_info(void)
{
int i;
printf("!!! Date of Birth must be entered as dd mm yy separated by space\n\n");
for(i=0; i<3; ++i)
{
printf("Student# %i\n", i+1);
printf("========================\n");
get_first_name(i);
get_last_name(i);
get_date_of_birth(i);
}
return 0;
}
void sort_array_by_month(void)
{
struct sStudent Temp;
int i, n, swap;
do
{
swap=0;
for(i=0; i<3; ++i)//bubble sort
{
if(Algebra[i].birthday.month>Algebra[i+1].birthday.month)
Temp=Algebra[i];
Algebra[i]=Algebra[i+1];
Algebra[i+1]=Temp;
swap=1;
}
}while(swap!=0);
}
main()
{
int i;
get_info();
sort_array_by_month();
for(i=0; i<3; ++i)
{
printf("%s %s", Algebra[i].first_name, Algebra[i].last_name);
printf("%15i/%i/%i\n", Algebra[i].birthday.day, Algebra[i].birthday.month, Algebra[i].birthday.year);
}
}
Also not sure but do I need to end string with a null character maybe like
Code:
Temp.first_name[n]='\0';
Temp.last_name[n]='\0'; and so on
Thank you for your help!!!