using namespace std;
struct karmand{
char nam[10];
char shomare[10];
char sx[10];
char mm[10];
char rgh[10];
}list[s];
void search();
void prin(int i);
void input_file();
void enter();
int a;
void menu_select(){
char p[10];
int c;
system("cls");
printf("1)enter a record:\n");
printf("2)sort the file:\n");
printf("3)search the file:\n");
printf("4)quit:\n");
do{
printf("please enter your choice:");
gets(p);
c=atoi(p);
}while(c<0||c>4);
system("cls");
switch(c){
case 1:enter();break;
case 2:search();break;
case 3:exit(1);
}
}
void load(){
FILE *fp;
if((fp=fopen("df.txt","r+"))==NULL){
printf("cannot open file");
getch();
exit(1);
}
int z=0;
while(!feof(fp)){
fscanf(fp,"%s",&list[z].nam);
fscanf(fp,"%s",&list[z].shomare);
fscanf(fp,"%s",&list[z].sx);
fscanf(fp,"%s",&list[z].mm);
fscanf(fp,"%s",&list[z].rgh);
z++;
a=z;
}
fclose(fp);
}
void search(){
char e[20];
int i;
printf("please enter jostoju:");
gets(e);
for(i=0;strlen(list[i].nam)!=0;i++){
if(strcmp(e,list[i].nam)==0){
prin(i);
}
else{
printf("cannot find");
}
}
}
void prin(int i){
printf("%s",list[i].nam);
printf("\t");
printf("%s",list[i].shomare);
printf("\t");
printf("%s",list[i].sx);
printf("\t");
printf("%s",list[i].mm);
printf("\t");
printf("%s",list[i].rgh);
printf("\n");
}
void enter(){
printf("enter name khanevadegi:");
scanf("%s",list[a].nam);
printf("\nenter shomare personeli:");
scanf("%s",list[a].shomare);
printf("\nenter jensiat:");
scanf("%s",list[a].sx);
printf("\nenter vaziate ta'ahol:");
scanf("%s",list[a].mm);
printf("\nenter vaziate estekhdam:");
scanf("%s",list[a].rgh);
input_file();
}
void input_file(){
FILE *out;
if((out=fopen("df.txt","w+"))==NULL){
printf("cannot open file");
getch();
exit(1);
}
for(int y=0;strlen(list[y].nam)!=0;y++){
fwrite(&list[y],sizeof(struct karmand),1,out);
fprintf(out,"\n");
}
fclose(out);
}
int main()
{
load();
enter();
menu_select();
return 0;
}
gu mi nam 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.