-3

I am trying to write a C program that takes in two arguments, either [-url | -phone | -email] and a text file that the user will download from a website.

After the user inputs the flag and the name of the text file, the program is supposed to extract and display the contents based on the regular expression I have developed.

For example, for URL the regex is /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/

I am having a hard time figuring out how I can implement such a task. Do I need to use fork()? How exactly can I read the data from the text file and display back results based on the regex?

Here is the example OUTPUT

$ gcc –o minor1 minor1.c  
$ ./minor1  
Usage:  
./minor1 [-url | -email | -phone] input_file  

URL CASE SCENARIO:

$./minor1 -url index.html  
https://www.web.edu/  
...  
http://webpreview.web.edu/  
...  
httpL//policy.web.edu/  

Based on the flag and the input file, this is what it is supposed to return

DYZ
  • 55,249
  • 10
  • 64
  • 93

1 Answers1

0

You may use curl to download the file from the web.

Then you can iterate and parse the data to extract the regex pattern of either url, email or phone.

Try to come out with some code yourself and if there is any problem, post what you did, snippet of the code that failed, and explain your own thoughts on why do you think it failed.

Community
  • 1
  • 1
dd22
  • 1