-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
100 lines (77 loc) · 2.26 KB
/
main.cpp
File metadata and controls
100 lines (77 loc) · 2.26 KB
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
#include <iostream>
#include <stdlib.h>
#include "pokedex.h"
#include "pokemon.h"
#include <fstream>
using namespace std;
Pokedex* fill_dex(string filename){
ifstream file(filename);
Pokemon * pokemon_list;
Pokemon * pokemon;
int f_total_pokemon;
int number;
string name;
string type;
string move1;
string move2;
string move3;
string move4;
cout << "Please enter your name: " << endl;
cin >> name;
file >> f_total_pokemon;
pokemon_list = new Pokemon[f_total_pokemon];
Pokedex * pokedex = new Pokedex(name, f_total_pokemon);
cout << "here";
for(int i = 0; i < f_total_pokemon; i++){
file >> number;
cout << i << ": " << number << endl; //DELETE LATER
file >> name;
cout << i << ": " << name << endl; //DELETE LATER
file >> type;
cout << i << ": " << type << endl; //DELETE LATER
pokemon = new Pokemon(number, name, type);
file >> move1;
file >> move2;
file >> move3;
file >> move4;
pokemon->set_moves(move1,move2,move3,move4);
pokemon_list[i] = *pokemon;
}
//cout << pokemon_list[1].get_name() << "PLEASE WORK" << endl;
pokedex->add_list(pokemon_list);
cout << pokedex->get_num();
pokedex->print_pokemon();
file.close();
return pokedex;
}
string read_file(char * filename){
string input = filename;
ifstream file;
file.open(input);
while(file.fail()){
file.close();
cout << "The file name you entered doesn't exist" << endl
<< "Make sure that the file extension is included and re-enter your file name: " << endl;
cin >> input;
file.open(input);
}
file.close();
cout << "file found" << endl << endl;
return(input);
}
void command_line_error(int argc){
if(argc != 2){
cerr << "ERROR: A FILE NAME WAS NOT GIVEN" << endl;
exit(EXIT_FAILURE);
}
}
int main(int argc, char *argv[]){
command_line_error(argc);
string filename;
filename = read_file(argv[1]);
Pokedex* pokedex;
pokedex = fill_dex(filename);
cout << "hello" << endl;
pokedex->print_pokemon();
return 0;
}