So I have this assignment for C course. I am quite lost about where to even start. Any help would be appreciated.
Read a URL (assume http protocol) as a string from stdin. Extract from the URL, the domain name, relative path name, name-value pairs in the query string. Print the following with appropriate ids.
the name-value pairs in the form "(name, value)"
You need to organize the program so that each task is accomplished by a function with minimal code clustering in the main program. For this assignment assume that URL has the format "http://...[?...=...&...&...=...]". The string that follows the ? is called query-string. It consists of name-value pairs separated by '&'. The name and the corresponding value are separated b '='. You may assume that the URLS are similar to the ones shown in the examples below. Assume that the valid URLS will have "https://" as a prefix. If the prefix is missing, treat it as an incorrect URL, print that with an error message, and continue to process the next line of input. You must implement and use the folliwng functions.
split(s,c,sl,sr) - splits a string s into two substring sl and sr. sl is the portion of the string to the left of c and sr is the portion following c. if the string does not contain c, sl is a copy of s and sr is empty string. This is a utility function called by other ........ions. It returns true if c is found in s, otherwise it returns false. s and c are input paramenters, and sl and sr are output parameters. Assume that all parameters are strings.
get_name_value(inp,name,value) - inp is input parameter (in general) of the form "name=value". name and value are output parameters. this function returns true if the string inp is of the correct form, otherwise retruns false. All parameters must be strings.
get_name_value_pair(s,nvp,tail) - splits a string s into two substrings nvp and tail. nvp is the portion of s preceding the first '&' in s, and tail is the substring following '&'. It returns true if s contains an '&', otherwise false. All must be strings.
get_domain(s,d) - extracts the domain d, from s
get_path(s,p) - extracts the path p from s
valid(s) - checks if the prefix of s is "http://". if the prefix is "http://" return 1, else return 0.
the functions get_name_value, get_name_value_pair, get_domain, and get_path must use the function split to extract the component strings.
You must use only the parameters specified.
assume one url at a time.
input - http://www.google.com/search?hl=en&q=ibm
Domain name: http://www.google.com
relative path name: search
name-value pairs are as follows: