Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- struct contact {
- int number; //Number cannot be more then 8 digits
- char name[50];
- };
- int main(){
- int number_of_contacts = 0,index=0;
- printf("Enter Number Of Contacts : ");
- scanf("%d",&number_of_contacts);//Input the length of array
- struct contact contacts[number_of_contacts]; //Define Structure array
- for(index = 0;index<number_of_contacts;index++){
- scanf("%s %ld",&contacts[index].name,&contacts[index].number);
- }
- //Searching Part
- char name[50];
- int found = 0,loc;
- printf("Enter Name To Search: ");
- scanf("%s",&name);
- for(index = 0;index<number_of_contacts;index++){
- if(strcmp(name,contacts[index].name) == 0){ //String Compare Function
- found = 1;
- loc = index;
- }
- }
- if(found == 1){
- printf("Index -> %d\n",loc);
- printf("Name -> %s\nNumber -> %d",contacts[loc].name,contacts[loc].number);
- }
- else{
- printf("Contact Not Found -> X ");
- }
- }
Add Comment
Please, Sign In to add comment