-
Please some help.
please a little help with this would be greatly appreciated.. the code is long but as you can see that when you load it. everything runs through then the searched don't work. i tried with 4 and it didn't work where is the problem please help.....
__________________________________________________ _
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
typedef struct list_data LD;
struct list_data
{
int id;
int wage;
int sex;
int age;
};
int arrange_id(const void *v1, const void *v2)
{
LD *a1=(LD *)v1;
LD *a2=(LD *)v2;
return (a1->id - a2->id);
}
int arrange_wage(const void *v1, const void *v2)
{
LD *a1=(LD *)v1;
LD *a2=(LD *)v2;
return (a1->wage - a2->wage);
}
int arrange_age(const void *v1, const void *v2)
{
LD *a1=(LD *)v1;
LD *a2=(LD *)v2;
return (a1->age - a2->age);
}
int main (void)
{
int c;
int d;
int e;
int t;
char sort;
int b, i;
LD a[10], *aptr=a;
printf("please enter the number of people that you wish to enter\n");
scanf("%d",&b);
printf("The number of people you will enter is =%d\n\n", b);
printf("Now enter the data\n\r");
for (i=1; i<=b; i++)
{
printf("please enter the ID of (person %d)\n", i);
scanf("%d",&a[i].id);
printf("please enter the Wage of (person %d)\n", i);
scanf("%d",&a[i].wage);
printf("please eter the Sex,(0 for male, 1 for female) of (person %d)\n", i);
scanf("%d",&a[i].sex);
printf("please enter the Age of (person %d)\n", i);
scanf("%d",&a[i].age);
}
printf("thank you the data will now be put into a table\n\r");
printf("Results\n\r");
printf("___________________________________\n\r");
printf("ID\t");
printf("Wage\t");
printf("Sex\t");
printf("Age\t\n\r");
for (i=1; i<=b; i++)
{
printf("%d\t",a[i].id);
printf("%d\t",a[i].wage);
printf("%d\t",a[i].sex);
printf("%d\t\n",a[i].age);
};
t=1;
while (t==1)
{
printf("How would you like to sort the inputted data?\n\r");
printf("If you want to sort ascending by ID, type 'a'\n\r");
printf("if you want to sort ascending by Wage, type 'b'\n\r");
printf("if you want to sort ascending by age, type 'c'\n\r");
printf("if you want to sort only females, type 'd'\n\r");
printf("if you want to sort only males type 'e'\n\r");
scanf("\n%c",&sort);
if(sort==a)
{
qsort(a, b, sizeof(LD), arrange_id);
}
else
{
if(sort=b)
{
qsort(a, b, sizeof(LD), arrange_wage);
}
}
if(sort==c)
{
qsort(a, b, sizeof(LD), arrange_age);
}
if(sort==d)
{
printf("no\n\r");/*insert sort here*/
}
if(sort==e)
{
printf("no\n\r");/*insert sort here*/
}
printf("Results\n\r");
printf("___________________________________\n\r");
printf("ID\t");
printf("Wage\t");
printf("Sex\t");
printf("Age\t\n\r");
for(i=1; i<=b; i++)
{
printf("%d\t",a[i].id);
printf("%d\t",a[i].wage);
printf("%d\t",a[i].sex);
printf("%d\t\n",a[i].age);
};
printf("would you like sort again\n '1' = yes\n '2' = no\n\r");
scanf("%d",&t);
}
return 0;
}
Popular pages
Recent additions