برنامج عن بيانات الطلاب يحتوي علي
insert data
delete
display
search
sort
help
exit
l
مااعرف كيف اشتغل ال sort&deleteارجو منكم المساعده :)
ا
insert data
display
search
help
exit
محتاج مساعده في sort &delete
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
struct date
{
int dd,mm,yy;
};
struct bdowner_data
{
char name[40],street[40],city[40],btype[40];
int num ;
int phone;
int age;
struct date d;
}dwnr;
struct bdowner_data data(struct bdowner_data dwnr)
{
int n=0;
char x;
FILE*f;
clrscr();
printf("enter the name[%d]:\n",n+1);
scanf("%s",dwnr.name);
printf("enter bdowner street:\n");
scanf("%s",dwnr.street);
printf("Enter the city :\n");
scanf("%s",dwnr.city);
printf("Enter the blood type :\n");
scanf("%s",dwnr.btype);
printf("Entrer the downer number:\n");
scanf("%d",&dwnr.num);
printf("Enter downer's phone:\n");
scanf("%d",&dwnr.phone);
printf("ENTER DOWNER'S AGE :\n");
scanf("%d",&dwnr.age);
printf("\nEnter the date :\n");
printf("\nDAY:");
scanf("%d",&dwnr.d.dd);
printf("MONTH:");
scanf("%d",&dwnr.d.mm) ;
printf("YEAR:");
scanf("%d",&dwnr.d.yy);
f=fopen("c:\\mashroo3\\cd.txt","a+");
fprintf(f, "%s\t %s\t %s\t%s\t %d\t %d\t %d\t %d\t %d\t%d\n",dwnr.name,dwnr.street,dwnr.city,dwnr.btype,dwnr.num,dwnr.phone,dwnr.age,dwnr.d.dd,dwnr.d.mm,dwnr.d.yy) ;
fclose(f);
printf("to enter a new downer's data please click on:**( y or Y)**:- \n");
scanf("%s",&x);
if((x=='y')||(x=='Y'))
return data(dwnr);
}
//----------------------------------------------------------------------
void display(FILE*f){ //display
int dd,mm,yy,i; char name[80],street[40],city[40],btype[40];
int num,phone,age;clrscr();
f=fopen("c:\\mashroo3\\cd.txt","r");
rewind(f);
do{ //case 4 ===display all downers
fscanf(f, "%s %s %s %s %d %d %d %d %d %d",name,street,city,btype,&num,&phone,&age,&dd,&mm,&yy) ;
printf("%s\t %s\t %s %s\t %d\t %d\t %d\t %d\t %d %d\n",name,street,city,btype,num,phone,age,dd,mm,yy);}
while (!feof(f));
fclose(f);
}
//----------------------------------------------------------------------
void search(FILE*f){ //search
int dd,mm,yy,i; char name[40],street[40],city[40],btype[40];
int num,phone,age;clrscr();
printf("Enter the downer number:");
scanf("%d",&i);
f=fopen("c:\\mashroo3\\cd.txt","r+");
rewind(f);
while(!feof(f)) //case 2====search for spesific custmer data
{
fscanf(f, "%s %s %s %s %d %d %d %d %d %d",name,street,city,btype,&num,&phone,&age,&dd,&mm,&yy) ;
if(num==i)
{
printf("%s\t %s\t %s\t %d\t %d\t %d\t %d\t %d\n",name,street,city,btype,num,phone,age,dd,mm,yy);
break;
}
}
fclose(f);
}
//----------------------------------------------------------------------
void update(FILE*f){
int dd,mm,yy,i; char name[40],street[40],city[40],btype[40];
int num, phone,age;clrscr();
printf("Enter the downer number:");
scanf("%d",&i);
f=fopen("c:\\mashroo3\\cd.txt","r");
rewind(f); //case 4===update
while(!feof(f))
{
fscanf(f,"%s %s %s %s %d %d %d %d %d %d ",name,street,city,btype,&num,&phone,&age,&dd,&mm,&yy) ;
if(num==i)
{
printf("Enter the name:");
scanf("%s",dwnr.name);
fclose(f);
f=fopen("c:\\mashroo3\\cd.txt","a");
rewind(f);
fprintf(f,"%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d%\t%d\t%d",name,street,city,btype,num,phone,age,dd,mm,yy) ;
break;
} else
printf("can not performed");
}
fclose(f);
}
//----------------------------------------------------------------------
void main()
{
FILE*f;int i,k; char pass[10] ,key[10]={"dede"},b;
struct bdowner_data dwnr; m:
clrscr();
printf("\t\t\t\tBY THE NAME OF ALLAH\n");
printf("\t\t\t\tTHE NATIONAL RIBAT UNIVERSITY\n");
printf("\t\t\t\tFACAULTY OF COMPUTER STUDIES\n");
printf("\t\t\t\tINFORMATION TECHNOLOGY\n");
printf("\t\t\t\t\t BATCH TEN \n");
printf("\n\n\n\n\t\t\t\t**FILE MANAGEMENT PROJECT**");
printf("\n\n\n\n\n\n\tPlease Enter the code of the system:**** \t");
/* //the password
*/
scanf("%s",pass);
//----------------------------------------------------------------------
k=(strcmp(pass,key));
if(k==0)
goto s;
else goto m;
a:s:clrscr();
printf("1-Insert blood downer data.\n2-Search for downer's data by downer number.\n3-Update blood downer data.\n4-Display all blood downer data.\n5-Exit.\n\n\n\n\n Please select the number of the operation:... ");
scanf("%d",&i);
switch (i){
case 1:data(dwnr);goto a;
case 2: {search(f);printf("Enter b to exit:");
scanf("%c",&;
if(b=='b')goto a;break;}
case 3:update(f); break;
case 4:display(f);break;
case 5: exit(0);}
getch();
}