How can I make my program load a file with a command line?

I wan't my program to require the user to load a file with a command line such as "program.exe fileToLoad.txt," or be able to just drag the file onto the exe file in explorer. It's a simple dos program and I am using C. How would I do this?

Comments

  • : I wan't my program to require the user to load a file with a command line such as "program.exe fileToLoad.txt," or be able to just drag the file onto the exe file in explorer. It's a simple dos program and I am using C. How would I do this?
    :

    Drag & drop requires a windows C++ program. For your first question, your program gets all command-line arguments as parameters to the main() function.
    [code]
    int main(int argc, char *argv[], char *env[])
    {
    // argc == number of command-line arguments. the first
    // argument is always the executable's name
    // argv == each of the arguments
    // env == all the environment variables, e.g. PATH

    if( argc > 1 )
    {
    // get the command-line argment, assumed to be
    // a filename.
    char *filename = argv[2];

    }
    }
    [/code]



    }

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