السلام عليكم ورحمة الله
هذا برنامج بسيط كتطبيق على الstructure
#include<stdio.h>
#include<conio.h>
int count=0;
struct fullname{
char fname[8];
char lname[8];
};
struct address{
char city[15];
char street[15];
};
struct college{
char cname[10];
int cID;
};
struct teacher{
int id;
struct fullname name;
struct address add;
struct college c;
double sal;
};
int pos(struct teacher s[],int id)
{
int i;
for(i=0;i<count;++i)
if (s.id==id)
return i;
return -1;
}
void add(struct teacher t[])
{
clrscr();
printf("Enter the ID of the teacher : \n");
scanf("%d",&t[count].id);
printf("Enter full name of teacher : \n");
scanf("%s %s",&t[count].name.fname,&t[count].name.lname);
printf("Enter your city and street : \n");
scanf("%s %s",&t[count].add.city,&t[count].add.street);
printf("Enter teacher college name : \n");
scanf("%s",&t[count].c.cname);
printf("Enter teacher college ID : \n");
scanf("%d",&t[count].c.cID);
printf("Enter the tecaher salary : \n");
scanf("%lf",&t[count].sal);
++count;
}
////////////////////////////////////
void del(struct teacher t[])
{
int id,i ,found;
clrscr();
printf("Enter id to delete: ");
scanf("%d",&id);
for(i=0;i<count;++i)
if(t.id==id)
{
for(i=i;i<count-1;++i)
t=t[i+1];
--count;
found=1;
printf("\nThe teacher %d Deleting ...",id);
}
if(found !=1)
printf("\nTeacher not found ..");
getch();
}
void search(struct teacher t[])
{
int id ,i,found;
printf("Enter id to search: \n");
scanf("%d",&id);
for(i=0;i<count;++i)
if(t.id==id)
{
printf("Teacher Founded ...");
printf("\n Full name : %s %s",t.name.fname,t.name.lname);
printf("\nAddres : %s %s",t.add.city,t.add.street);
printf("\nCollege : %s %d",t.c.cname,t.c.cID);
printf("\nSalary : %lf",t.sal);
found=1;
}
if (found !=1)
printf("\nTeacher not Found ...");
getch();
}
void display(struct teacher t[])
{
int i;
clrscr();
printf("\n%-5s%-10s%-10s%-10s%-10s%-12s%-10s%-8s","ID","Fname","Lname","City","Street","College name","College ID","Salary");
for(i=0;i<count;i++)
{
printf("%-5d%-10s%-10s%-10s%-10s%-12s%-10d%-8f",t.id,t.name.fname,t.name.lname,t.add.city,t.add.street,t.c.cname,t.c.cID,t.sal);
}
getch();
}
void sort(struct teacher t[])
{
char temp[8];
int i;
for(i=0;i<count;i++)
{
if(strcmp(t.name.fname ,t[i+1].name.fname)>0)
{
strcpy(temp,t.name.fname);
strcpy(t.name.fname,t[i+1].name.fname);
strcpy(t[i+1].name.fname,temp);
}
}
}
void tCount(struct teacher t[])
{
int i,gcount,rcount;
for(i=0;i<count;i++)
{
if(strcmp(t.add.city,"gaza")==0)
++gcount;
if(strcmp(t.add.city,"rafah")==0)
++rcount;
}
printf("\nThe number of teachers lives in Gaza : %d",gcount);
printf("\nThe number of teachers lives in Rafah : %d",rcount);
getch();
}
void maxSal(struct teacher t[])
{
int max=0,i;
for(i=0;i<count;i++)
{
if(t.sal>max)
max=t.sal;
}
printf("\nThe maximus salary : %f",max);
getch();
}
void menu()
{
printf("\n=========================");
printf("\n\t\t Main Menu \t\t");
printf("\n|| 1- Add teacher ||");
printf("\n|| 2- List Teachers Information ||");
printf("\n|| 3- Sort Teachers ||");
printf("\n|| 4- Search ||");
printf("\n|| 5- Delete a Teacher ||");
printf("\n|| 6- Display the sum of Gaza and Rafah teachers ||");
printf("\n|| 7- Display Maximus Salary ||");
printf("\n|| 8- Exit ||");
}
int main()
{
int no;
char ans;
struct teacher t[20];
do{
menu();
printf("\Choose number : ");
scanf("%d",&no);
switch(no)
{
case 1: add(t);
break;
case 2: display(t);
break;
case 3: sort(t);
break;
case 4: search(t);
break;
case 5: del(t);
break;
case 6:tCount(t);
break;
case 7: maxSal(t);
break;
case 8: exit(0);
break;
}
printf("\nProcess..?");
printf(" .... Enter y for yes or n for no ....");
scanf("%c",ans);
}while ((ans!='n')||(ans!='N'));
getch();
return 0;
}به خطأ في هذا الجزء
void add(struct teacher t[])
{
clrscr();
printf("Enter the ID of the teacher : \n");
scanf("%d",&t[count].id);
printf("Enter full name of teacher : \n");
scanf("%s %s",&t[count].name.fname,&t[count].name.lname);
printf("Enter your city and street : \n");
scanf("%s %s",&t[count].add.city,&t[count].add.street);
printf("Enter teacher college name : \n");
scanf("%s",&t[count].c.cname);
printf("Enter teacher college ID : \n");
scanf("%d",&t[count].c.cID);
printf("Enter the tecaher salary : \n");
scanf("%lf",&t[count].sal);
++count;
}حيث لا يأخذ الsalary ويخرج من البرنامج
هل يعرف احدكم ما هي المشكلة ؟؟