This needs to be done in C language. This was the previous code:
#include <stdio.h>
int main() {
int n;
char buffer[1000];
while(1) {
printf("Enter phone number: ");
if(scanf("%d", &n)) {
if(n == 0) {
break;
} if(n >= 1000000 && n <= 9999999) {
printf("%d-%d\n", n/10000, n%10000);
} else {
printf("Invalid number '%d'\n", n);
}
} else {
fgets(buffer, 1000, stdin);
printf("Invalid number %s", buffer);
}
}
return 0;
}
Remember what we learned in Lab#02? North American telephone numbers always follow the following structure: 3-digit area code + 3-digit central office code + 4-digit subscriber. For example, the Algonquin College main phone number is "(613) 727-4723" where the area code is "613", the central office (or exchange) is "727", and the subscriber is "4723". Neither the area code nor the central office code will ever start with the digit "0" or "1". Print your 10-digit number in the format: 613727-4723.
You will:
Represent each phone entry by a unique 7-digit phone number (3-digit central office code + 4-digit subscriber), 3-digit Area code, Last Name, and First Name. Represent each Area with a 3-digit Area code (416) and Area Name (e.g., Toronto). You will create five Areas as mentioned above.
When your program runs, it will ask for 5 choices:
1. Enter the details of that student.
2. If you choose option 2, you will have to enter a 3-digit area code to get the details of all the students who have phone numbers with that area code.
3. If you choose option 3, you will have to enter the last name of the student to get the details of that student.
4. If you choose option 4, you will get the details of all the listed area codes.
5. Enter 'q' to quit your program.
Sample output may look like:
$./asg1
Choose one of the five following options:
Press [1] to get information based on phone number.
Press [2] to get information based on Area Code.
Press [3] to get information based on Last Name.
Press [4] to print all area-code information.
Press [q] to quit.
You pressed: 1
Enter Area Code: 416
Enter 7-digit number: 2345678
Your 10-digit phone number is: 416-2345678
Phone number 416-2345678 belongs to the student Last1, First1, and his number is from Toronto.