473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C++11 , How to get the entire NYSE listing daily?

rollerbladegirl
69 64KB
In C++11.

On a Windows computer.

How do I add to my program a way for it to download from the internet the entire NYSE listing daily?

I am still learning C++11.

If you give an example that is stable, and it is really simple, then I can go from there.

Code that is baby level simple please.

Thanks.
Jan 23 '20 #1
5 1811
SioSio
272 256MB
This program to get the source by specifying the URL and save it in a binary file.(Only Windows)
Expand|Select|Wrap|Line Numbers
  1. #include "pch.h"
  2. #include <iostream>
  3.  
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #include <wininet.h>
  7. #include <tchar.h>
  8. #include <locale.h>
  9.  
  10. #pragma comment(lib,"wininet.lib")
  11.  
  12. //      Get data from the specified URL and save it in a file in binary
  13. int webBinGet(HINTERNET hInet, TCHAR* url, FILE* fp);
  14.  
  15. int _tmain(int argc, TCHAR** argv) {
  16.     HINTERNET hInet;
  17.     FILE* fp;
  18.  
  19.     //      Sets the locale to display UNICODE characters correctly on stderr
  20.     _tsetlocale(LC_ALL, _TEXT(""));
  21.  
  22.     if (argc != 3) {
  23.         _ftprintf(stderr, _TEXT("Usage : This_Prog_Name.exe [url] [save file name]\n"));
  24.         return 1;
  25.     }
  26.     //Start Internet connect(WinInet)
  27.     hInet = InternetOpen(TEXT("wxz123"),
  28.         INTERNET_OPEN_TYPE_PRECONFIG,
  29.         NULL, NULL, 0);
  30.     if (hInet == NULL) {
  31.         _ftprintf(stderr, _TEXT("Failure the handl eacquisition\n"));
  32.         return 2;
  33.     }
  34.     if (_tfopen_s(&fp, argv[2], TEXT("wb"))) {
  35.         InternetCloseHandle(hInet);
  36.         _ftprintf(stderr, _TEXT("File Open Error %s\n"), argv[2]);
  37.         return 3;
  38.     }
  39.     if (webBinGet(hInet, argv[1], fp) < 0)
  40.         _ftprintf(stderr, _TEXT("Could not load source from internet successfully\n"));
  41.     InternetCloseHandle(hInet);
  42.     fclose(fp);
  43.     return 0;
  44. }
  45.  
  46. //      Get HTML source from the URL and save binary file.
  47.  
  48. int webBinGet(HINTERNET hInet, TCHAR* url, FILE* fp) {
  49.     char buf[1024];
  50.     HINTERNET hUrl;
  51.     //HTTP session Start,and URL open.
  52.     hUrl = InternetOpenUrl(hInet, url, NULL, 0, 0, 0);
  53.     if (hUrl == NULL) {
  54.         _ftprintf(stderr, _TEXT("URL Open Error %s\n"), url);
  55.         return -1;
  56.     }
  57.     //Read to the end
  58.     int len;
  59.     int size = 0;
  60.     for (;;) {
  61.         InternetReadFile(hUrl, buf, sizeof(buf), (LPDWORD)&len);
  62.         if (len <= 0)
  63.             break;
  64.         fwrite(buf, sizeof(buf[0]), len, fp);
  65.         size += len;
  66.     }
  67.     InternetCloseHandle(hUrl);
  68.     return len;     //      Return File size.
  69. }
  70.  
After that, create a part to find your required tag and get the value in bin file.

If you run at a fixed time every day,
Use time scheduling(Wiindows).
Jan 24 '20 #2
rollerbladegirl
69 64KB
SioSio YES !

Thank you.

And it uses Unicode ! Yes again! Again Thank You. I wanted this program to be usable by any Unicode user. I have been starting with #define _UNICODE and #define UNICODE.

Direct, to the point, a bit of a stretch to keep up with it, but it looks like code that I can study and learn from.

OH, I LIKE THIS SITE !

I see that you use #include "pch.h". I have read about this and it seems to be used in some examples with Visual Studio. Does that mean that I have to use VS to use this code.

I am using CODE::BLOCKS 17.12 and GNU GCC Compiler.

My main is int WINAPI WinMain(...). I am compiling to a Windows GUI. I hope that if I study your code example that I can use it. It looks nice.

And, with #include "pch.h", does that mean that, in my final compiled program, that my headers will be compiled separately? I wanted the entire program to be one single executable with no dlls, etc. I have been using #define IDC_STATIC (-1). Or, does #include "pch.h" just make the compilation faster. Can I use this code without #include "pch.h"?

Really, Thanks SioSio.
Jan 24 '20 #3
rollerbladegirl
69 64KB
I am looking up your code (parts) and studying it and it seems to be written for Visual Studio. I am not getting the following to work:

Expand|Select|Wrap|Line Numbers
  1.     if (_tfopen_s(&fp, argv[2], TEXT("wb"))) {
  2.         InternetCloseHandle(hInet);
  3.         _ftprintf(stderr, _TEXT("File Open Error %s\n"), argv[2]);
  4.         return 3;
I looked up _tfopen_s and it does not seem to work outside of Visual Studio. I am trying to find how to do the VS parts in C or C++ by itself without VS.

Thanks.
Jan 24 '20 #4
SioSio
272 256MB
Yes, this source was written in VS.

#include "pch.h" is not required if the environment is not VS.

In Visual Studio, fopen cannot be used as it is (it is necessary to write #pragma warning (disable: 4996) at the beginning of the source), so use _fopen_s.
Expand|Select|Wrap|Line Numbers
  1. _tfopen_s(&fp、argv [2]、TEXT( "wb"))
  2.  
  3. fp = fopen(argv[2], "wb");
  4.  
Jan 25 '20 #5
rollerbladegirl
69 64KB
Thank you SioSio.

Last summer 2019 I decided to learn C++11.

I have no interest in using Visual Studio (at this time).

As a new C++ programmer, it has taken me sometimes hours to convert VS stuff to C++ code. Now I have been trying to stay away from VS studio stuff.

Your offer to help me with VS code was nice. I appreciate the offer. Thank you. But, I am looking for C++11 code.

At your level of expertise, maybe you can supply that code in C++? I can use any version of C++ up to 11 and I can use straight C. Would you please help me with doing this in C++ (up to C++11)?

Thank you SioSio.
Jan 28 '20 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Kim Jensen | last post by:
I'd like to make a directory listing where instead of the entire filename I need it to show the filename minus the extention and get the value of charname= in the file itself. I've been told...
2
by: M A Srinivas | last post by:
Hello all, I have the following requirement (SQL 2000, SP2) 1. Need to restore production database(A) to another database (B) on another server (No direct connection) 2. In the restored...
1
by: httpmart | last post by:
On my website I routinely make use of anchors such as: <a name="shipping">SHIPPING</a> and a link to them such as: <a href="#shipping">Go to Shipping information</a> These work fine on IE.
19
by: SU News Server | last post by:
I've struggled with this for quite a while and I'm am just not sure what is going on. I have the following code import os def buildList( directory='/Users/mkonrad' ) dirs = listing =...
5
by: Craig Alexander Morrison | last post by:
I have not seen the FAQ daily post recently is this group being discontinued. -- Slainte Craig Alexander Morrison
3
by: Charlie | last post by:
I am fairly new to VB.NET and was wondering if anyone knew where to find a complete listing of the namespaces in VB.NET and MSDN Library. I would really like to see a listing or a "catalog" of...
8
by: gil | last post by:
Is it possible to prevent a browser from listing the entire contents of a folder? The site, is hosted on my ISP with the following layout- site/ "user name from ISP" pagefile (dir)...
0
by: JonCl | last post by:
Hello, I'm thinking of creating a Windows service to backup a small enterprise system running on an Oracle database. My idea is to create a Windows service on the main server and also each remote...
5
by: tickletantrum | last post by:
This question was asked once on Bytes.com, but the 'asker' was Amateur to say the least and the question was never fully answered. So here is the question. I am designing a page containing a...
46
by: brikusi | last post by:
Please help, I have a database whereby i am tracking attendance on a daily basis, however i may need to update the table more than once in the day as people enter the service later after...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.