All Projects

Bus Ticket Booking System in Python
Bus Ticket Booking System in Java
Bus Ticket Booking System in Cpp
Bus Ticket Booking System in C
Cafe Order System in Python
Cafe Order System in Java
Cafe Order System in Cpp
Cafe Order System in C
Social Media Account Details Manager in Python
Social Media Account Details Manager in Java
Social Media Account Details Manager in Cpp
Social Media Account Details Manager in C
Mini ATM in Python Language
Mini ATM in Java Language
Mini ATM in cpp language
Mini ATM in c language
Pocket Money Manager in Python Language
Pocket Money Manager in Java Language
Pocket Money Manager in Cpp Language
Pocket Money Manager in C Language
Username Password Generator in Python Language
Username Password Generator in Cpp Language
Username Password Generator in C Language
Telephone Directory in Python Language
Telephone Directory in Java Language
Telephone Directory in Cpp Language
Telephone Directory in C Language
Calander in Cpp Language
Calander in C Language
NoteBook in Python Language
NoteBook in Cpp Language
NoteBook in C Language
Voting System in Python Language
Voting System in Java Language
Voting System in Cpp Language
Voting System in C Language
Age Calculator in Python Language
Age Calculator in Java Language
Age Calculator in Cpp Language
Age Calculator in C Language
Currency Converter in Python Language
Currency Converter in Java Language
Currency Converter in Cpp Language
Currency Converter in C Language
Random Password Generator in python language
Random Password Generator in java language
Random Password Generator in cpp language
Random Password Generator in c language
Billing System in python language
Billing System in c++ language
Billing System in c language
Atm in c language

Telephone Directory in C Language


Aniket The Programmer

1K+ Subscribers

Click To Subscribe My Channel

Subscribe

Source Code

        
#include <stdio.h>
#include <string.h>

#define MAX_CONTACTS 100

struct Contact {
    char name[50];
    char telephone[20];
    char address[100];
    char relationship[50];
};

struct Contact directory[MAX_CONTACTS];
int contactCount = 0;

void addContact() {
    if (contactCount < MAX_CONTACTS) {
        struct Contact newContact;
        printf("Enter name: ");
        scanf("%s", newContact.name);
        printf("Enter telephone number: ");
        scanf("%s", newContact.telephone);
        printf("Enter address: ");
        scanf("%s", newContact.address);
        printf("Enter relationship: ");
        scanf("%s", newContact.relationship);

        directory[contactCount] = newContact;
        contactCount++;
        printf("Contact added successfully!\n");
    } else {
        printf("Directory is full.\n");
    }
}

void showContacts() {
    if (contactCount == 0) {
        printf("No contacts in the directory.\n");
    } else {
        printf("Contacts in the directory:\n");
        for (int i = 0; i < contactCount; i++) {
            printf("Contact %d:\n", i + 1);
            printf("Name: %s\n", directory[i].name);
            printf("Telephone: %s\n", directory[i].telephone);
            printf("Address: %s\n", directory[i].address);
            printf("Relationship: %s\n", directory[i].relationship);
            printf("\n");
        }
    }
}

void updateContact() {
    if (contactCount == 0) {
        printf("No contacts in the directory to update.\n");
    } else {
        char name[50];
        printf("Enter the name of the contact to update: ");
        scanf("%s", name);
        int found = 0;
        for (int i = 0; i < contactCount; i++) {
            if (strcmp(directory[i].name, name) == 0) {
                printf("Enter new telephone number: ");
                scanf("%s", directory[i].telephone);
                printf("Enter new address: ");
                scanf("%s", directory[i].address);
                printf("Enter new relationship: ");
                scanf("%s", directory[i].relationship);
                printf("Contact updated successfully!\n");
                found = 1;
                break;
            }
        }
        if (!found) {
            printf("Contact not found.\n");
        }
    }
}

void deleteContact() {
    if (contactCount == 0) {
        printf("No contacts in the directory to delete.\n");
    } else {
        char name[50];
        printf("Enter the name of the contact to delete: ");
        scanf("%s", name);
        int found = 0;
        for (int i = 0; i < contactCount; i++) {
            if (strcmp(directory[i].name, name) == 0) {
                for (int j = i; j < contactCount - 1; j++) {
                    directory[j] = directory[j + 1];
                }
                contactCount--;
                printf("Contact deleted successfully!\n");
                found = 1;
                break;
            }
        }
        if (!found) {
            printf("Contact not found.\n");
        }
    }
}

int main() {
    int choice;
    do {
        printf("\nTelephone Directory\n");
        printf("1. Add Contact\n");
        printf("2. Show Contacts\n");
        printf("3. Update Contact\n");
        printf("4. Delete Contact\n");
        printf("5. Exit\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                addContact();
                break;
            case 2:
                showContacts();
                break;
            case 3:
                updateContact();
                break;
            case 4:
                deleteContact();
                break;
            case 5:
                printf("Exiting program. Goodbye!\n");
                break;
            default:
                printf("Invalid choice. Please enter a valid option.\n");
        }
    } while (choice != 5);

    return 0;
}
        
    

Source Code Github Link: View

View Video On Youtube Link: View