0

Hi,

I'm new to APIs. Got the code below to compile (with 3 warnings C4129) but it won't output to the designated path. I created the txt file ahead of time, nqquotes.txt, but after the code compiles, that file stays empty.

Thanks for your help,
TR

#include "stdafx.h"
#include <tchar.h>
#include <urlmon.h>
#include <iostream>
using namespace std;
#pragma comment(lib, "urlmon.lib")

int main()
{
    cout << "downloading NQ data from Quandl...";
    HRESULT hr = URLDownloadToFile 
        ( NULL, _T("https://www.quandl.com/api/v1/datasets/CME/NQH2015.csv"),_T("C:\users\my documents\visual studio 2008\projects\nq data\nqquotes.txt"), 0, NULL);

cout << "Done!" << endl;

    system("PAUSE");
}
3
Contributors
4
Replies
23
Views
2 Years
Discussion Span
Last Post by toneranger
0

Thank you Suzie.

You mean checking as in something like this?

if (hr == S_OK) ?

0

You mean checking as in something like this?

if (hr == S_OK) ?

Yes.

The main problem with your code is that the szFileName in URLDownloadToFile is invalid.
"C:\users\my documents\visual studio 2008\projects\nq data\nqquotes.txt"
should be either
"C:\\users\\my documents\\visual studio 2008\\projects\\nq data\\nqquotes.txt"
or
"C:/users/my documents/visual studio 2008/projects/nq data/nqquotes.txt"

It's also not necessary to pre-create the text file. If URLDownloadToFile is successful then the text file will be created.

Edited by nullptr

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.