linux newbie

how do u take in a pathname as a command line argument so u can traverse the directories or files in that path?

Comments

  • : how do u take in a pathname as a command line argument so u can traverse the directories or files in that path?
    :
    :

    I expect you are using c/c++ for your application:

    #include
    #include
    using namespace std;

    int main(int argc, char *argv[])
    {
    char path[256];

    if (argc == 1)
    {
    cerr << "Error: Please give pathname as argument!
    ";
    exit(1);
    }

    strcpy(path, argv[1]);
    cout << "Path: " << path << endl;
    }

    So, argc is a counter which shows you how much arguments are given to your application by the shell. argv is c-string vector. You can take other names than argc or argv but it's the standard way!

    If you have other questions, write me!


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion