I'm wanting to search a file full of http links.. I know how to search for a string and such but I don't know how I would search for a link inside a file.

I just basically want to search a index.html for a certain site pertaining to ..lets say http://www.blah.com, and copy that entire link into an output file..but my problem lies at stuff like http://www.blah.com/hjahsJS or http://www.blah.com/jse833.. How would I copy the entire link? The index.html code I'm wanting to search, has < after every link. Just hoping for some pointers.

I do not have any code to show right now, I pretty much know the basics of I/O..except this part. And School is over, had my last finals last night. This is just a personal project.

Thanks for any help.

Recommended Answers

All 2 Replies

This seems to me like it is just a delimiting problem...

That is, if each link is separated by "<", then u simply need to copy each character that occurs up until this...

Unless I am over-simplifying the problem, all I would do is just a tokenized approach: move through the file character by character. Then you just need to set up a few checks to make sure you are still reading a link (i.e. make sure the character is not a "<", and copy it. You can do this by creating a "PeekCharacter" function, i.e. by storing each character in some sort of buffer and then performing the test...). I would almost be inclined to set up a list structure to store the data...

Hopefully that helps...but I may have misinterpreted your problem..

move through the file character by character.

It would work, but it a bit too 'C' for my taste. How about using the getline() function with a third parameter as delimiter?

ifstream file("yourfile.txt");
if (file)
{
    std::string word;
    std::vector <std::string> array;
    while ( getline(file, word, '<'))
        array.push_back(word);
}

This doesn't account for spaces tabs and newlines off course, but it's a simple program that stores strings in a vector from a file delimited with a '<'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.