Bring structs to life! You'll define a Contact struct and fill an array of contacts from user input, then print them all back neatly.
YOUR TASK
Write a C program that:
Defines a struct Contact with fields: name (char[50]) and phone (char[20])
Reads n contacts from input
Prints each contact formatted as Name: ... | Phone: ...
Need a hint?
Step-by-step:
1. Define the struct before main: typedef struct { char name[50]; char phone[20]; } Contact;
2. Read n, then declare Contact book[n];
3. For each contact use scanf("%s %s", book[i].name, book[i].phone);
4. Loop to print: printf("Name: %s | Phone: %s\n", ...);
Example (input: 2, Alice 555-1234, Bob 555-5678):
Name: Alice | Phone: 555-1234
Name: Bob | Phone: 555-5678
Code Editor
Ready
Output
Console
Console initialized...
Ready for Project 4: Contact Book with Structs
> Test your code with the "Check My Code" button
> When it passes, the Complete button will unlock!