August 2000
CA208 : 'C' PROGRAMMING

QUESTION 2

Total Marks: 15 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 2

You are to implement a simple system which is used to store details of all the web pages accessed by a computer user. A web page is identified by the protocol type, which can be one of http, ftp, or cgi ; a URL (Uniform Resource Locator), which is a string of arbitrary length, and a server address, which is the composition of four numbers in the range 0 – 255 (i.e., four 8-bit numbers).
Consider the following definition of a list in C, which can be used to store details of web pages:
  typedef struct ListElement {
  WebPage Page;
  struct ListElement* NextPage;
} LE;

(a) Define a suitable enumerated type, called Protocol, which can take on any of the three protocol values http, ftp, or cgi. [1 mark]

(b) Define the data structure WebPage, such that it contains the protocol type, a pointer to a string containing the URL, and each of the four 8 bit numbers which make up the server address. You may assume that the data type char is an 8 bit wide type. [4 marks]

(c) Implement a function, called Find, the signature of which is given below, which takes a reference to a ListElement, and a reference to a WebPage and returns 1 if the WebPage is found in the list, or 0 otherwise. You may use the function Match, the signature of which is given below, which returns 1 if both parameters are identical, and 0 otherwise. You are not required to implement Match
int Match(Webpage a, WebPage b);
int Find(const ListElement* L, WebPage* W); [5 marks]

(d) Implement a function, called LastURL, which takes a reference to a ListElement and will return a reference to the URL of the last WebPage stored in the list The function should not be allowed to change the LastURL. [5 marks]