I am trying to open a file from a command line argument.
I've debugged my program:
when I print the value of file it gives the value <incomplete type>.
when I print the value of argv it gives the value (char **) 0x7fffffffe4e0.
when I print the value of argv[1] it gives the value 0x0.
The function won't open my file. Not sure why?
Ive tried:
if (file.is_open()) too and same problem.
BSTTreeData buildBST (char *argv[]){
vector <string> allwords;
BSTTreeData Data;
BinarySearchTree<string> Tree;
ifstream file (argv[1]);
char token;
string listofchars = "";
string input;
int distinct = 0;
int line = 1;
if (file){
//if the file opens
while (getline(file, input)) //gets every line in the file
{
for (int i = 0; i < input.size(); ++i) //gets all the contents in the line
{
token = input[i]; //each character become a 'token'
if (isalpha(token))
{
//if the character is an alphabetical character
listofchars += token; //append character to a string
if (Contains(allwords, listofchars) == false)
{
//if the current word has not already been added to vector of words
//increment the distinct word count
distinct += 1;
Tree.insert(listofchars); //creates the BST
allwords.push_back(listofchars); //add current word to vector of all the w\
ords
}
else
line++; //increments the line number
}
else
line++; //increments the line number
}
listofchars = ""; //creates empty character string
}
file.close(); //closes file
Data.BST = Tree;
Data.linenumber = line;
Data.distinctwords = distinct;
Data.words = allwords;
return Data;
}
}