K
KL
Hey...I am working on a project for school. I preface this so everyone
understands that I don't want the full answer, rather a nudge in the
correct direction.
The following code section is supposed parse in a url from the command
line. For some reason, I am not parsing the command line properly. Can
someone help nudge me towards the correct way to do this?
int main(int argc, char *argv[]) {
int sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
cout << "cannot create socket" << endl;
exit(1);
}
for (int a=0; a<argc; ++a){
string url, hostname, filename;
// get rid of the initial "http://" characters
url=argv[a];
url.erase(0,7);
hostname = url;
filename = url;
int loc = hostname.find("/",0);
if (loc != string::npos) {
hostname.erase(loc);
filename.erase(0,loc);
}
else {
filename = "/";
}
--
KL
______________________________00
_______________________0000000000
______________________00___00___00
__________________________00____00
_________________________00_____00
________________________00______00
________________000____00_______00
___________________00000000000000000
_____________________00_________00_000
____________________00__________00
____________________00__________00
___________________00___________00
_______00________00_____________00
_________00______00______________00___
___________000000_________________00000
********ROLL TIDE*********
understands that I don't want the full answer, rather a nudge in the
correct direction.
The following code section is supposed parse in a url from the command
line. For some reason, I am not parsing the command line properly. Can
someone help nudge me towards the correct way to do this?
int main(int argc, char *argv[]) {
int sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
cout << "cannot create socket" << endl;
exit(1);
}
for (int a=0; a<argc; ++a){
string url, hostname, filename;
// get rid of the initial "http://" characters
url=argv[a];
url.erase(0,7);
hostname = url;
filename = url;
int loc = hostname.find("/",0);
if (loc != string::npos) {
hostname.erase(loc);
filename.erase(0,loc);
}
else {
filename = "/";
}
--
KL
______________________________00
_______________________0000000000
______________________00___00___00
__________________________00____00
_________________________00_____00
________________________00______00
________________000____00_______00
___________________00000000000000000
_____________________00_________00_000
____________________00__________00
____________________00__________00
___________________00___________00
_______00________00_____________00
_________00______00______________00___
___________000000_________________00000
********ROLL TIDE*********