fork(2) download
  1. In the early nineties, the World Wide Web (WWW) was invented. Nowadays, most people think that the WWW simply consists of all the pretty (or not so pretty) HTML-pages that you can read with your WWW browser. But back then, one of the main intentions behind the design of the WWW was to unify several existing communication protocols.
  2.  
  3. Then (and even now), information on the Internet was available via a multitude of channels: FTP, HTTP, E-Mail, News, Gopher, and many more. Thanks to the WWW, all these services can now be uniformly addressed via URLs (Uniform Resource Locators). The syntax of URLs is defined in the Internet standard RFC 1738. For our problem, we consider a simplified version of the syntax, which is as follows:
  4.  
  5. <protocol> "://" <host> [ ":" <port> ] [ "/" <path> ]
  6.  
  7. The square brackets [] mean that the enclosed string is optional and may or may not appear. Examples of URLs are the following:
  8.  
  9. http://w...content-available-to-author-only...m.de/acm
  10. ftp://a...content-available-to-author-only...r.edu:1234/pub/staff/mr-p
  11. gopher://veryold.edu
  12.  
  13. More specifically,
  14.  
  15. <protocol> is always one of http, ftp or gopher.
  16.  
  17. <host> is a string consisting of alphabetic (a-z, A-Z) or numeric (0-9) characters and points (.).
  18.  
  19. <port> is a positive integer, smaller than 65536.
  20.  
  21. <path> is a string that contains no spaces.
  22.  
  23. You are to write a program that parses an URL into its components.
  24.  
  25.  
  26. Input
  27.  
  28. The input starts with a line containing a single integer n, the number of URLs in the input. The following n lines contain one URL each, in the format described above. The URLs will consist of at most 60 characters each.
  29.  
  30.  
  31. Output
  32.  
  33. For each URL in the input first print the number of the URL, as shown in the sample output. Then print four lines, stating the protocol, host, port and path specified by the URL. If the port and/or path are not given in the URL, print the string <default> instead. Adhere to the format shown in the sample output.
  34.  
  35. Print a blank line after each test case.
  36.  
  37.  
  38. Sample Input
  39.  
  40. 3
  41. ftp://a...content-available-to-author-only...r.edu:1234/pub/staff/mr-p
  42. http://w...content-available-to-author-only...m.de/acm
  43. gopher://veryold.edu
  44.  
  45.  
  46. Sample Output
  47.  
  48. URL #1
  49. Protocol = ftp
  50. Host = acm.baylor.edu
  51. Port = 1234
  52. Path = pub/staff/mr-p
  53.  
  54. URL #2
  55. Protocol = http
  56. Host = www.informatik.uni-ulm.de
  57. Port = <default>
  58. Path = acm
  59.  
  60. URL #3
  61. Protocol = gopher
  62. Host = veryold.edu
  63. Port = <default>
  64. Path = <default>
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:1: error: unknown type name ‘In’
 In the early nineties, the World Wide Web (WWW) was invented. Nowadays, most people think that the WWW simply consists of all the pretty (or not so pretty) HTML-pages that you can read with your WWW browser. But back then, one of the main intentions behind the design of the WWW was to unify several existing communication protocols.
 ^
prog.c:1:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘early’
 In the early nineties, the World Wide Web (WWW) was invented. Nowadays, most people think that the WWW simply consists of all the pretty (or not so pretty) HTML-pages that you can read with your WWW browser. But back then, one of the main intentions behind the design of the WWW was to unify several existing communication protocols.
        ^
prog.c:1:8: error: unknown type name ‘early’
prog.c:48:5: error: stray ‘#’ in program
 URL #1
     ^
prog.c:54:5: error: stray ‘#’ in program
 URL #2
     ^
prog.c:60:5: error: stray ‘#’ in program
 URL #3
     ^
stdout
Standard output is empty