>>957
#include <stdio.h>
struct URL {
char host[256];
int port;
char path[256];
};
int parse(const char* raw, struct URL *url)
{
url->port = 80;
url->path[0] = '\0';
if(sscanf(raw, "http://%[^:/]:%d%s", url->host, &url->port, url->path) == 3)
return 0;
if(sscanf(raw, "http://%[^:/]%s", url->host, url->path) == 2)
return 0;
if(sscanf(raw, "http://%[^:/]", url->host) == 1)
return 0;
return 1;
}
int main()
{
struct URL url;
if(parse("http://www.hoge.com/usr/bin/hoge.txt", &url) == 0){
printf("ホスト名 %s\n", url.host);
printf("ポート番号 %d\n", url.port);
printf("パス %s\n", url.path);
} else {
printf("エラー\n");
}
return 0;
}