INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

using URLDownloadToFile for multiple links in a file

using URLDownloadToFile for multiple links in a file

using URLDownloadToFile for multiple links in a file

(OP)
ok, I'm going to try to explain this the best way possible, so here it goes:

I am trying to run URLDownloadToFile, using links from a file, so It would read the first link, process it, save it to a file, read the next link, process it, save it to the same file.

Problem is that even if i put it in a function, that is called from a loop, that it will process the first link, save all the info that I want, then overwrite the info from the first link with the second link, then go back and process the first link again and over write the second link info:

here is the code:

CODE

string line;
    ifstream flink;
    ifstream fin;
    ifstream fin2;
    ofstream fout;
    ofstream fout2;
    std::string plink;
    string start = "profile\"";
    string end = "</a>";
    string tbod = "<tbody>";
    string etbod = "</tbody>";
    string slink = "<a href=";
    bool tbody = false;
    string Name;
    
    
    flink.open("playerlinks.txt");
    std::string str; LPCSTR lpcstr = str.c_str();
    getline(flink, plink);
    while(flink)
    {
        
        cout << (LPCSTR)plink.c_str() << endl;
       
        ProcsLink(plink);
            {
            //Some other code for saving info
                fout2 << nPname << " ";
        fout2 << ntname;
        fout2 << endl;
        }
        flink >> plink;
    
    cout << "hi" << endl;
    system("PAUSE");
    //return 0;

    
    }
}

here is the function that is supposed to handle the link:

CODE

void ProcsLink(string plink)
{
    string line;
    
    ifstream fin;
    
    ofstream fout;
        
    string start = "profile\"";
    string end = "</a>";
    string tbod = "<tbody>";
    string etbod = "</tbody>";
    string slink = "<a href=";
    bool tbody = false;
    string Name;
    
        HRESULT hr = URLDownloadToFile(NULL, (LPCSTR)plink.c_str(), _T("test2.txt"), 0, NULL);
    
        fin.open("test2.txt");
        fout.open("test3.txt");
        while(fin.good())
        {
        
            getline(fin, line);

            if(line.find(tbod) != string::npos)
            {
                tbody = true;
            }
            if(line.find(etbod) != string::npos)
            {
                tbody = false;
            }
            if(line.find(start) != string::npos && tbody == true)
            {
                
                
                fout << line;
                
            }
            else if(line.find(slink) != string::npos && tbody == true)
            {
                
                fout << line;
                fout << endl;
                
            }    
        }
}
 

RE: using URLDownloadToFile for multiple links in a file

Pass the next file name as a second parameter of ProcsLink. Generate new names or extract names from links in the main loop:

CODE

bool ProcsLink(const string& link, const string& fname)
{
    ...
}
...
for (int fno = 0; getline(flink,link); ++fno) {
    ostringstream ss;
    ss << "test" << fno << ".txt";
    string fname(ss.str());
    ProcsLink(link,fname);
    ...
}
Avoid passing std::string arguments by value (it's ineffective method), use references.

It seems the true problems with your code are error testing and download synchronization.

Are you sure that new thread on the same topic is OK?..
 

RE: using URLDownloadToFile for multiple links in a file

(OP)
Thanks that worked

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close