How are you?
I'm trying to write a program that, among other things, needs to validate a website. Basically I need to know if a user-entered website exists or not. I don't know where to start. I was wondering if you could give me a lead with this. How to do this using C/C++ Thank you so much!
The standard C++ library does not provide any facility to do this. You have to use a third-party library for this.
You could use libcurl, a free, open source, widely portable client-side URL transfer library.
The documentation on using libcurn from C/C++ is here: http://curl.haxx.se/libcurl/c/
Programming with the library is simple, for example this is how you would use libcurl in unix (FreeBSD):
curl_global_init( CURL_GLOBAL_ALL ) ;
CURL* handle = curl_easy_init() ;
curl_easy_setopt( handle, CURLOPT_HEADER, 1 ) ;
curl_easy_setopt( handle, CURLOPT_NOBODY, 1 ) ;
curl_easy_setopt( handle, CURLOPT_FOLLOWLOCATION, 1 ) ;
curl_easy_setopt( handle, CURLOPT_MAXREDIRS, 10) ;
// suppress all output by sending it to the null device
FILE* null_device = std::fopen( "/dev/null", "w" ) ;
curl_easy_setopt( handle, CURLOPT_WRITEDATA, null_device ) ;
std::string url ;
while( std::cout << "url? " && std::cin >> url )
curl_easy_setopt( handle, CURLOPT_URL, url.c_str() ) ;
if( curl_easy_perform( handle ) != 0 )
std::cerr << "the url '" << url << "' does not seem to exist or is inaccessible\n" ;
std::cerr << "a site with the url '" << url << "' was found\n" ;
compile and link using gcc:
g++44 -Wall -std=c++98 -pedantic -Werror -lcurl -I /usr/local/include -L /usr/local/lib program.cc
a site with the url 'google.com' was found
a site with the url 'www.google.com' was found
the url 'http:/www.google.com' does not seem to exist or is inaccessible
a site with the url 'http://www.google.com'
the url 'zebra.org' does not seem to exist or is inaccessible