1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
/* Carter Young
October 17, 2013
Trying to get to yahoo finance and
dowload the historical prices for
amount of time*/
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <windows.h>
#include <math.h>
int main()
{
// To initialize the variables
char my_stock[10], new_stock[10], company_name[100], freq[10];
int start_month, start_day, start_year;
int end_month, end_day, end_year;
char s_month[10], s_day[10], s_year[10];
char e_month[10], e_day[10], e_year[10];
// To read in the stock from the user
printf("What is the stock ticker that you would like to use?\n");
scanf("%s", &my_stock);
// To read in the start date from the user
printf("Please enter the date you would like to start with\n");
scanf("%d", &start_month);
scanf("%d", &start_day);
scanf("%d", &start_year);
// To read in the end date from the user
printf("Please enter the date you would like to end with?\n");
scanf("%d", &end_month);
scanf("%d", &end_day);
scanf("%d", &end_year);
// To print out dates and verify accuracy
printf("The data will start on %d/%d/%d and end on %d/%d/%d\n",
start_month, start_day, start_year, end_month, end_day, end_year);
// To determine frequency of his price
printf("At what frequency would you like to pull the prices: Daily (d),\n Monthly (m), or yearly (y)?\n");
scanf("%s", &freq);
// To decrease start and end months by one to conform to url string
start_month--;
end_month--;
// To convert integer variables into strings to converge into url string
itoa(start_month, s_month, 10);
itoa(start_day, s_day, 10);
itoa(start_year, s_year, 10);
itoa(end_month, e_month, 10);
itoa(end_day, e_day, 10);
itoa(end_year, e_year, 10);
// To build the yahoo finance url and print it out
char s1[100] = "http://finance.yahoo.com/q/hp?s=";
strcat(s1, my_stock);
char s2[10] = "&a=";
strcat(s2, s_month);
char s3[10] = "&b=";
strcat(s3, s_day);
char s4[10] = "&c=";
strcat(s4, s_year);
char s5[10] = "&d=";
strcat(s5, e_month);
char s6[10] = "&e=";
strcat(s6, e_day);
char s7[10] = "&f=";
strcat(s7, e_year);
char s8[10] = "&g=";
char s9[15] = "&ignore=.csv";
strcat(s8, freq);
strcat(s1, s2);
strcat(s1, s3);
strcat(s1, s4);
strcat(s1, s5);
strcat(s1, s6);
strcat(s1, s7);
strcat(s1, s8);
strcat(s1, s9);
printf("%s\n\n", s1);
// To open of the url
ShellExecute(NULL, "open", s1, NULL, NULL, SW_SHOWNORMAL);
return 0;
}
|