Created
August 19, 2016 05:43
-
-
Save sks147/b326a58f10126d67d74a286cbc3b5789 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int server_start_index; | |
int server_end_index; | |
int main(){ | |
string url; | |
cin>>url; | |
cout << "Retrieving the server :" << endl; | |
string http = "http://"; | |
string https = "https://"; | |
int begin = 0; | |
if(url.substr(0, 7) == http ){ | |
begin = 7; | |
} | |
if(url.substr(0, 8) == https){ | |
begin = 8; | |
} | |
//cout << begin << endl; | |
string www = "www."; | |
if(url.substr(begin, 4) == www){ | |
server_start_index = begin+4; | |
} | |
//cout << server_start_index<<endl; | |
int server_end_index = 0; | |
for(int i=server_start_index; i<url.length(); i++){ | |
if(url[i] == ':'){ | |
server_end_index = i; | |
break; | |
} | |
} | |
int server_length = server_end_index-server_start_index; | |
string server_name = url.substr(server_start_index, server_length); | |
cout << "Server name is : " << server_name << endl; | |
int port_start_index = server_start_index+server_length+1; | |
string port = url.substr(port_start_index, 4); | |
cout <<"Port Number is : "<< port << endl; | |
int file_start_index = 0; | |
for (int i = port_start_index; i < url.length(); ++i) | |
{ | |
if(url[i] == '/'){ | |
file_start_index = i+1; | |
} | |
} | |
int file_length = url.length()-file_start_index; | |
string file_name = url.substr(file_start_index, file_length); | |
cout << "File name : " << file_name << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment