In: Computer Science
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone."
Write a program to extract the phone numbers and store them in the output file.
Example input/output:
Enter the file name: input_names.txt
Output file name: phone_input_names.txt
1) Name your program phone_numbers.c
2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume the length of each line in the input file is no more than 10000 characters.
3) The program should include the following function: void extract_phone(char *input, char *phone); The function expects input to point to a string containing a line in the “First_Last_Phone” form. In the function, you will find and store the phone number in string phone.
Comments would be helpful as well Thanks
/ Java program to read all mobile numbers
// present in given file
import
java.util.regex.*;
import
java.io.*;
class
MobileNumberExtraction
{
public
static
void
main(String[]
args)
throws
IOException
{
//
Write Mobile Numbers to output.txt file
PrintWriter
pw =
new
PrintWriter(
"output.txt"
);
//
Regular expression for mobile number
Pattern
p =
Pattern.compile(
"(0/91)?[7-9][0-9]{9}"
);
//
BufferedReader for reading from input.txt file
BufferedReader
br =
new
BufferedReader
(
new
FileReader(
"input.txt"
));
String
line = br.readLine();
while
(line !=
null
)
{
Matcher
m = p.matcher(line);
while
(m.find())
{
//
Write the mobile number to output.txt file
pw.println(m.group());
}
line
= br.readLine();
}
pw.flush();
}
}