Jiang Bian Jiang Bian - 1 month ago 12
C Question

Best ways of parsing a URL using C?

I have a URL like this:

http://192.168.0.1:8080/servlet/rece


I want to parse the URL to get the values:

IP: 192.168.0.1
Port: 8080
page: /servlet/rece


How do I do that?

Answer

Write a custom parser or use one of the string replace functions to replace the separator ':' and then use sscanf().