I am trying to obtain text from a .txt file online. The .txt file either contains "Yes" or "No". Is there a way I can download using winsock2.h or ws2_32.lib?
So basically im trying to get "Yes" or "No" into a variable. I have read a lot on this subject and I am prepared to read more if someone can point me in the right direction.
I am trying to keep the compiled file size down, so using,
#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "Urlmon.lib")
constchar szFileName[] = "Download.txt";
constchar szUrl[] = "www.yoururl.com";
bool show_file()
{
// TODO
// read the file and print the content.
}
int main()
{
// https://msdn.microsoft.com/en-us/library/ms775123(v=vs.85).aspx
HRESULT result = URLDownloadToFile(0, szUrl, szFileName, 0, 0);
switch (result)
{
case INET_E_DOWNLOAD_FAILURE:
printf("\a\nThe specified resource or callback interface was invalid.");
break;
case E_OUTOFMEMORY:
printf("\a\nThe buffer length is invalid, or there is insufficient memory to complete the operation.");
break;
case S_OK:
printf("Success downloading...");
show_file();
break;
}
system("pause");
return 0;
}