Read all lines

How can this code:
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>

using namespace std;

enum tToken 
{
    PLUS, MINUS, MUL, DIV, LPAR, RPAR, NUMBER, END, ERROR
};

tToken Token;        
double TokenValue;

char *srcPos;           // Program position

tToken searchToken() {
    Token = ERROR;
    if (srcPos==0) {
        Token = END;
    } else {
        switch (*srcPos)
        {
            case '(': Token=LPAR;  break;
            case ')': Token=RPAR;  break;
            case '*': Token=MUL;   break;
            case '/': Token=DIV;   break;
            case '+': Token=PLUS;  break;
            case '-': Token=MINUS; break;
        }
		if (*srcPos>='0' && *srcPos<'9') {
            Token=NUMBER;
            TokenValue = 0.0;
        }
        while (*srcPos>='0' && *srcPos<'9') {
            TokenValue *= 10;
            TokenValue += *srcPos-'0';
            srcPos++;
        }
		if (Token != NUMBER) {
            srcPos++;
        }
    }
    return Token;
}

tToken Error(char *s){
	cout << s << endl;
    return ERROR;
}

double PlusMinus();

double tal() {
    double Value;
    switch(Token) {
        case NUMBER:
            searchToken();
            return TokenValue;
        case MINUS:
            searchToken();
            return -tal();
        case LPAR:
            searchToken();
            Value = PlusMinus();
            if (Token != RPAR) {
				return Error(") expected");}
            {
            searchToken();
            return Value;
        case END:
            return 1;
			}
	}
    return Error("Primary expected");
}

double MulDiv() {
    double Value;
    Value = tal();
    while (Token==MUL || Token==DIV) {
        if (Token==MUL)
        {
            searchToken();
            Value *= tal();
        } else if (Token==DIV) {
          searchToken();
          Value /= tal();
        }
    }
    return Value;
}

double PlusMinus() {
    double Value;
    Value = MulDiv();
    while (Token==PLUS || Token==MINUS) {
        if (Token==PLUS) {
            searchToken();
            Value += MulDiv();
        } else if (Token==MINUS) {
            searchToken();
            Value -= MulDiv();
        }
    }
    return Value;
}

double Utvardering(char *s) {
    srcPos = s;
    searchToken();      // Determines the first token in advance
    return PlusMinus();
}

int main(int argc, char* argv[]) {
    // Display the application information
    cout << "CERES Interpreter 0.1 ALPHA" << endl;
    cout << "Written by James Brooks 2009" << endl;
    cout << "Based on code by ogranatw" << endl;
    if (argc > 1) {
        const int MAX_SIZE = 1024;
        char buf[MAX_SIZE];
        FILE* fFile = fopen(argv[1], "r");
        if (!fgets(buf, MAX_SIZE, fFile)) {
          Error("Script file could not be executed!");
          exit(1);
        }else{
            printf("%s\n", buf);
            double Value = Utvardering(buf);
            cout << Value << endl;
        }
    }else{
        // Woops the user made a mistake
        cout << "Usage: " << argv[0] << " -scriptfile" << endl;
    }
    cin.get();
    return 0;
}

So far I have edited it to take input from a file through argv[1]. However it only reads the first line of output. How can I expand this to read all lines?
Do you want to read the entire file, or line by line?
Line by line.

2+2
5/3

Etc. I was thinking of using a ; to denote the end of a line.
1
2
3
4
5
6
7
8
9
std::ifstream file(name);
std::vector<std::string> lines;
while (1){
	std::string line;
	std::getline(file,line);
	if (!file.good())
		break;
	lines.push_back(line);
}
Where does that go?
Topic archived. No new replies allowed.