Experienced Programmers Pls See This

Pages: 12
Closed
Last edited on

void IndexDetails::MatchPattern()
{
int num; int ptr = 0;
num = line.length();
while(ptr<num)
{


I don't see where ptr is incremented.
A few comments:

if(strcmp("Dow",index_name.c_str())== 0)

index_name is a string, its c_str() method is returning a C string (null-terminated array of char), and then strcmp is comparing two C strings.

You could 'get rid of the middle man' and just compare index_name with "Dow", like this:
 
if( index_name == "Dow" )



1
2
3
string check("id"); size_t found; int y; int digi;
//...
digi = (int)found;

I'm not a big fan of explicit casting, especially C-style casting. Consider making y and digi size_t's:
1
2
3
string check("id"); size_t found; size_t y; size_t digi;
//...
digi = found;

Last edited on
Lol, you should be glad if the experienced dudes replying on the forum won't read this code,
they will curse at system("PAUSE")
Closed
Last edited on
I think you should pull ptr++ (line 116) within the else instead of none, because now your not using your loop, it checks for the condition in the first time the loop runs and if it doesn't give anything it'll just say None...
Not much use, program still outputs infinite loop. Somewhere my logic is supposedly wrong, I jus dunno where?
Looking at the code I see:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void IndexDetails::getValue()
{
     string check1("span"); size_t found; int y = 0; int digi;
     
     while(x < line.length())
   {
     for(int v = 0; v <8; v++)
     {
       disc = (line.find(name_value[v]));
            if(disc != string::npos)
            {
                 z = (int)disc;
                 while (line[z] != ' ')
                 {
                   index_name += line[z];
                   z++;
                 }
            cout << index_name << endl;
            } 
       MatchPattern();   
     } 
     x++;               
  }

may be the hanging part.
index_name is never initialized
line[z] could never reach a blank
etc.
The only way is debugging it.
See aft debugging I realise, that although the readFile function calls getName function, the program never goes there, I dunno why. Can someone pls test & make some changes for me?I would be really grateful, it has been days since I m trying 2 get this program to work.
I can have a look, if you post a sample of the finance.htm input file
post your html please..
<div id="yfi_streaming_quotes"><div id="yfsbar"><span id="yfs_onoff"></span><span id="yfs_wthis" style="display:none;"><a href="http://help.yahoo.com/l/us/yahoo/finance/quotes/quote-63.html">What are streaming quotes?</a></span></div><input type="hidden" id=".yficrumb" name=".yficrumb" value="pI5IEw6aK/n"></div><span id="yfs_common_params" class="yfs_common_params">{ "market" : {"NAME" : "U.S.", "ID" : "us_market", "TZ" : "ET", "TZOFFSET" : "-18000", "open" : "", "close" : "", "flags" : {}} , "STREAMER_SERVER" : "http://streamerapi.finance.yahoo.com","arrowAsChangeSign" : false,"throttleInterval": "1000"}</span>

I couldn't post everything. I basically took it from Yahoo Finance Singapore, view source of page.
hey, this code works for me.. i copied the html from http://sg.finance.yahoo.com/
hope this could help you, you can tweak it for better code.

note: this is not a good code, (this is actually a very dirty code)

hope it helps anyway.. good luck!

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
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <stdlib.h>
#include <sstream>
using namespace std;

int main() {
    ifstream inFile ("finance.htm");
    string array[] = {"Dow", "Nasdaq", "Hang Seng"};
    string line, buf, search;
    size_t found;

    //dump the html
    while(!inFile.eof()) {
        getline(inFile, buf);
        line += buf;
    }

    for(int x=0; x<3; x++) {
        search = array[x];
        found = line.find(search+"</a>");
        if(found!=string::npos) {
            cout << "searching found..\n";
            cout << line.substr(found, search.length());
            string tmp = line.substr(found, search.length()+100);
            stringstream ss( tmp );
            while(!isdigit(ss.peek())) ss.ignore();
            char output[256];
            ss.get(output, 256, ' ');
            cout<< endl << output ;
            cout << "\n==================\n";
        }
    }

    inFile.close();
    return 0;
}
Last edited on
Closed
Last edited on
what compiler are you using and what is the error you're getting from my code above? it compiles well on visual c++ 2008 and MingW..

here's the exe try it.. http://www.4shared.com/file/210889791/34189374/prog.html
Last edited on
I m using Dev C++ compiler, have pmed u. My heartfelt gratitude if u can get the program working.

Anyone else having a solution to my program, pls don't hesitate to post. This program is really getting on my nerves.
hey, i downloaded dev c++ and i dont get any error on compiling the above code.. tell me if that code above if something like what you're doing then i'll try to put it in your code to fix it..
Ok I guess, I shud explain.

The first function readFile stores the entire file contents into a string called line which is a private variable in my class. This helps me to do string manipulation easily.

readFile function then calls the getName function which finds the start position of each of the index names specified & stores the name in another private variable called index_name in my class.

Once the first index name is stored, getName calls the MatchPattern function which does a comparison with every keyword to see if the index_name & keyword match. Next I call a function getValue to get the index value associated with each index name.

I need to output index name & their corresponding index value. Lastly I need a function which can find the date this Yahoo Finance HTML page info was captured.

That's about it blackcoder41, thanks.
i have to goto school buddy, i'll work with that later.. you got my email right? i'll post later..

don't give up..
i have emailed you the exe and code! you just have to improve it..
Pages: 12