Step 4: Build the Permanent Main Menu Loop

Easy Section 1: Project Foundation
Solve in Playground →

Problem Statement

Create the permanent command-line application loop and menu router. Retain the complete Contact structure, global phonebook storage, contact counter, function framework, and initialization output from Task 3.

Add a choice variable and a loop that displays the menu, reads a menu choice, and routes choices through switch-case.

Choice 1 must call add_contact,
choice 2 must call display_contacts,
choice 3 must call search_contact,
choice 4 must call update_contact,
choice 5 must call delete_contact, and
choice 0 must terminate the application.

Invalid choices must produce an error message and continue the loop. The existing module functions remain intact and are called rather than reimplemented inside main.

Input Format

A sequence of integer menu choices terminated by 0.

Output Format

Print the initialization lines, then print Menu: before each choice. Choices 1 through 5 print the corresponding module placeholder message, choice 0 prints Exit and terminates, and any other value prints Invalid Choice.

Constraints

The final input is always 0. Choices may be any integer. The existing five module functions must be called from the corresponding switch cases. The loop must continue after every non-zero choice.

Sample Input

1 2 3 5 0

Sample Output

Contact Book Ready.
Phonebook Capacity: 100
Contacts: 0
Modules Ready.
Menu:
Add
Menu:
Display
Menu:
Search
Menu:
Delete
Menu:
Exit

Explanation

The permanent application loop and switch-case are established before feature implementation begins. This ensures that later tasks only fill the existing module functions and never need to replace or restructure the project's control flow.

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() {

}

void display_contacts() {

}

void search_contact() {

}

void update_contact() {

}

void delete_contact() {

}

int main() {
    printf("Contact Book Ready.");
    printf("\nPhonebook Capacity: %d", sizeof(phonebook)/sizeof(phonebook[0]));
    printf("\nContacts: %d", contact_count);
    printf("\nModules Ready.");
    // Write your code here
    
    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