I have a problem with searching in an array of structures. Please help Here is the code I have tried so far:
#include <stdio.h>
#include <stdlib.h>
typedef struct{
long long unsigned num;
char name[20];
}Telbook;
int be(Telbook*);
void ki(Telbook*);
void search (Telbook*);
int main(){
printf("\t\t\t \n\n\n");
Telbook tomb[50];
int db;
//Telbook *array=tomb;
db=be(tomb);
ki(tomb);
search(tomb);
system("pause");
}
int be(Telbook *n){
int i=0;
printf("Enter phone # and names until the phone # you entered is 0\n");
/*printf("Kérek egy nevet: ");
scanf("%s",n->name);*/
printf("Enter a Phone #: ");
scanf("%llu",&n->num);
while(n->num){
printf("Enter a name: ");
scanf("%s",n->name);
i++;
n++;
printf("Enter a phone #: ");
scanf("%llu",&n->num);
}
return i;
}
void ki(Telbook *n){
int i=0;
while(n[i]->num){
printf("Name: %s, Phone #: %llu\n",n[i]->name,n[i]->num);
i++;
}
}
void search(Telbook *n){
int i;
int db=be(Telbook *n);
char nev[20];
printf("Enter the name you're searching for: ");
scanf("%s",nev);
for(i=0;i<db;i++){
if(n[i].name==nev)break;
printf("%s",n[i.name]);
}
if(i==db){
printf("The name doesn't exist'.\n");
}
else{
printf("The name you have searhed for is: %s it's on the %d. index.\n",nev,i+1);
}
}
Like I would like to search for the name in the struct.