English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am programming in visual c/c++, using C not c++, and I have written a program that calls a file I input into it. When I run the program I have it asking what file I want to input but I would like to change this so I tell it that file when I call the program from the command prompt.

Ex. C:\Documents and Settings\user>program.exe file

if someone could help me out with that it would be very appreciated.

2006-08-29 03:45:16 · 2 answers · asked by jacobtyker 1 in Computers & Internet Programming & Design

2 answers

All you need to do is change
int main() {...
to
int main(int argc, char *argv[]) {...
This gives you an array of all the command line arguments.

2006-08-29 04:23:52 · answer #1 · answered by knbel 2 · 0 0

#include

int main(int argc, char *argv[])
{
}

The char* argv[] is your command Line argument, use it to read the file name and then pass that to your program

2006-08-29 11:23:35 · answer #2 · answered by bostoncity_guy 2 · 1 0

fedest.com, questions and answers