#include
#include
#include
#include
#include
extern "C" {
#include
//#include
#include
}
using namespace std;
int writer(char* data, size_t size, size_t nmemb, string *buffer) {
fprintf(stderr, "Hello, I am a function pointer\n");
int result = 0;
if (buffer != NULL) {
buffer->append(data, size * nmemb);
result = size * nmemb;
}
return result;
}
int main(int argc, char** args) {
CURL* curl; // That is the connection, see : curl_easy_init
CURLcode res; // Not needed, see : curl_easy_cleanup
string buffer; // see: CURLOPT_WRITEDATA
curl = curl_easy_init(); // Initilize web query
if (curl) {
// set options for web query
curl_easy_setopt(curl, CURLOPT_URL, args[1]);
curl_easy_setopt(curl, CURLOPT_HEADER, 0); // No we don't need the header of the web content, Set to 0 and
// curl ignores the first line
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0);//Don't follow anything else than the particular url requested
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer); // Function Pointer 'writer' manages the required buffer size
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); // Data Pointer &buffer stores downloaded web content
} else {
fprintf(stderr, "Error 1\n");
return 0;
}
res = curl_easy_perform(curl);
//string s = (res);
cout << res << endl;
curl_easy_cleanup(curl);
std::istringstream iss(buffer);
string line, item;
int linenum = 0;
while (getline(iss, line)) {
linenum ++;
cout << "\nline #" << linenum << " : " << endl;
std::istringstream linestream(line);
int itemnum = 0;
while (getline(linestream, item, ',')) {
itemnum ++;
cout << "Item # " << itemnum << " : " << item << endl;
}
}
return 0;
}