set up terminal line command help

hello people,

I have already written my code but i am stuck at the last part where it says i have to set up a flag for the command line. My program was to implement avl and BST trees and perform certain operations. I am done with that.

Now i need to test my program like
testTrees <document file name> <words file name> <flag> where flag is 0 for BST and 1 for AVL tree. guys please help how would i even get started. After some research i found its got to do with the argv, argc in the main line but no good example anywhere. please help...........
Last edited on
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

int main(int argc, char* argv[])
{
    std::cout << "The number of args you passed in is: " << argc << std::endl;
    for(int i = 0; i < argc; i++)
    {
        std::cout << "Argument " << i << " is: " << argv[i] << std::endl;
    }
    return 0;
}

This will show you how you can get arguments from the command line into variables you can use in your program.
./myProgram bacon moreBacon 5 3.1
The number of args you passed in is: 5
Argument 0 is: myProgram
Argument 1 is: bacon
Argument 2 is: moreBacon
Argument 3 is: 5
Argument 4 is: 3.1

Keep in mind that even if you pass in an argument like 1 or 3.5, it is still char form! You'll have to take your numeric arguments and change them from char strings into numbers if you want to use them like numbers.
Last edited on
Last edited on
Thank you booradley60 and rcast it helps but still i did not figure out how would i set a flag as 0 for BST and 1 for AVL tree
Last edited on
Simply pass 0 or 1 as the third argument when calling the program, and have the program handle if third console argv is 0 then BST else than AVL
thanks again for reply but after i started to implement this command function,my whole main function is messed up. This is first time i am handling two text files in a program.
Can you please guide me how do i implement my main? I do not need code just please check my steps.
1)created a BST class.
2)created an AVL class and was supposed to use inheritance.
3)now for the main i am conused

I open the first file. I stored as vectors i had to print line number i cannot figure out how to print line number of the word. //problem
insert as a tree. //done
asked the user to enter a word to search and print if it exists. //done
found the average depth, log2(n) and ratio of both. //done

now my problem starts
how would i read second file there. //problem
Last edited on
Topic archived. No new replies allowed.