Step 5: Read the Contact ID

Easy Section 2: Add Contact Module
Solve in Playground →

Problem Statement

Begin implementing the add_contact module. Retain the complete program created in Task 4 and add code inside add_contact() to read an integer contact ID from the user and display the entered ID. No validation is required yet. The existing main loop, switch-case menu, global storage, and all five module functions must remain intact.

Input Format

A menu choice of 1, followed by one integer contact ID, followed later by a menu choice of 0 to exit.

Output Format

After selecting Add, print the entered ID using the exact format: ID: [id].

Constraints

The ID may be any integer at this stage. The phonebook capacity is 100 contacts.

Sample Input

1
101
0

Sample Output

Contact Book Ready.
Phonebook Capacity: 100
Contacts: 0
Modules Ready.
Menu:
Add
ID: 101
Menu:
Exit

Explanation

The Add Contact workflow begins by capturing the identifier for the new contact. Validation is intentionally deferred to the next task so students build the workflow incrementally.

Starter Code

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

struct Contact {
    int id;
    char name[50];
    char phone[15];
};

struct Contact phonebook[100];
int contact_count = 0;

void add_contact();
void display_contacts();
void search_contact();
void update_contact();
void delete_contact();

void add_contact() {
// Write your code here

}

void display_contacts() {

}

void search_contact() {

}

void update_contact() {

}

void delete_contact() {

}

int main() {
    int choice;

    printf("Contact Book Ready.");
    printf("\nPhonebook Capacity: %d", sizeof(phonebook)/sizeof(phonebook[0]));
    printf("\nContacts: %d", contact_count);
    printf("\nModules Ready.");

    while (1) {
        printf("\nMenu:");

        if (scanf("%d", &choice) != 1) {
            break;
        }

        switch (choice) {
            case 1:
                printf("\nAdd");
                add_contact();
                break;

            case 2:
                printf("\nDisplay");
                display_contacts();
                break;

            case 3:
                printf("\nSearch");
                search_contact();
                break;

            case 4:
                printf("\nUpdate");
                update_contact();
                break;

            case 5:
                printf("\nDelete");
                delete_contact();
                break;

            case 0:
                printf("\nExit");
                return 0;

            default:
                printf("\nInvalid Choice");
                break;
        }
    }

    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used