Random

Thanks.
Last edited on
The first thing that's wrong is that it should be in code tags.
No, I am running this program on a C++ compiler. I have a header file, finpro.h and my main file is finpro.cpp. I have included the header file in my main program. The problem is the compiler keeps showing me the error that it can't link my header and main cpp files. This is even when I tested using a sample program.Now, I dunno what to do.When I run this program, the compiler tells me that it doesn't recognise the string data type nor are void functions permitted in my class, what's the issue I dunno so it would really be useful if some kind soul could look through my program and tell me what's wrong.I also wanted to know something, strtok is used for tokenising a string. As u can see, my functions return variables of type string so I can't use strtok bcose that deals with char* so now how do I do tokenisation and get the function to return me a string?
hehe LOL, what tummychow means format your post so we can easily read it.. look at the format button beside the text area when you type your post..
http://cplusplus.com/articles/firedraco1/
Done
Last edited on
The code goes in the code tags. You don't put the code tags up at the top and leave the code floating down at the bottom.
// Issues and resolution
Main() should not be in the same source file as finpro.cpp, it should be in another file (like main.cpp)

///////// finpro.cpp /////////
error :
while((token = str.next()) != " ")

It can be:
for( int i = 0; (token = str[i]) != ' '; ++i )
It is suggested that you should not be assigning variables within a condition expression.

//----

error :
if(0==strcmp("Dow",c_word))

fix:
if(0==strcmp("Dow",c_word.c_str())

error :
else if((0==strcmp("Nasdaq",c_word))||(0==strcmp("nasdaq",c_word)))

fix:
Same as previous error. strcmp only takes char * as a second parameter not string types.

///////// main.cpp /////////
error : ifstream inFile;
fix: std::ifstream inFile;


Here is your code fixed up:

Nothing wrong with finpro.h so it isn't included below.

main.cpp
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
#include "finpro.h"

int main()
{
	std::ifstream inFile;
inFile.open("A1_finance.txt");

FinanceApp temp;

if(!inFile)
{
cout << "The file does not exist. " << endl;

return 1;
}
else
{
string alpha;

getline(inFile, alpha);
temp.indexCheck(alpha);
}
inFile.close();
system("pause");

return 0;
}


finpro.cpp
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
#include "finpro.h"

FinanceApp::FinanceApp()
{
index = " ";
num = 0.0;
diff = 0.0;
}
string FinanceApp::getWord(string str)
{
string token, store;
for( int i = 0; (token = str[i]) != ' '; ++i )
{
store = str[i];
}

return store;
} 

void FinanceApp::indexCheck(string fin_value)
{
int num, ptr = 0; string c_word;
num = fin_value.length();
c_word = getWord(fin_value);
while(ptr<num)
{
if(0==strcmp("Dow",c_word.c_str()))
{
cout << "Testing: 1" << endl;
}
else if((0==strcmp("Nasdaq",c_word.c_str()))||(0==strcmp("nasdaq",c_word.c_str())))
{
cout << "Testing: 2" << endl;
}
else if(0==strcmp("S&P 500",c_word.c_str()))
{
cout << "Testing: 3" << endl;
}
else if(0==strcmp("FTSE 100",c_word.c_str()))
{
cout << "Testing:3" << endl;
}
else if(0==strcmp("DAX",c_word.c_str()))
{
cout << "Testing:4" << endl;
}
else if((0==strcmp("Nikkei 225", c_word.c_str()))||(0==strcmp("NIKKEI 225",c_word.c_str())))
{
cout << "Testing: 5" << endl;
}
else if((0==strcmp("Hang Seng", c_word.c_str()))||(0==strcmp("HANG SENG",c_word.c_str())))
{
cout << "Testing: 6" << endl;
}
else 
{
cout << "Testing: 7 " << endl;
}


}
}
Last edited on
@tummychow, ok now I understand.

@Always Learning, thanks a lot.
Last edited on
I'm not sure. You will probably need a network library such as WinSock, but I'm no expert on the matter; you might want to check online.
Topic archived. No new replies allowed.