Below is my program in console format. Can anyone tell me how to convert it to a command line program. We didn't really go over it in class so I have no idea how to do it. Also startGamePieceLocation.horzLocation and startGamePieceLocation.vertLocation have to be pulled from the same line as the command to start the program (i.e program.exe A4; im guessing not sure how you do it)
I think what s/he meant to ask is: "how would you write a program where you can specify its internal arguments from the command line e.g. program_name.exe -h "this" -t "that" ?" or something like that...
@JockX yeah the int main (int argc, char* argv[]) is what I was looking for.
@Matrix X No not that. I believe it would be more like program_name.exe text_file_name.txt startingLocation but I don't know how to start programs in the command line.
Starting location should be a string "A4" (for example). Then I need to store
startingLocation.at(0) into startGamePieceLocation.horzLocation and startingLocation.at(1) into startGamePieceLocation.vertLocation as an integer.
So something like:
1 2 3 4 5 6 7
int main (int argc, char* argv[])
{
startGamePieceLocation.horzLocation = startingLocation.at(0);
startGamePieceLocation.vertLocation = startingLocation.at(1) - 64;
return 0;
}
but replacing startingLocation with whatever "A4" is actually called (Which I don't know because i'm new to command line)
int main (int argc, char* argv[])
{
//assume user called "program.exe A4". Then:
// argc = 2;
// argv[0] = "program.exe"
// argv[1] = "A4"
startGamePieceLocation.horzLocation = argv[1][0]; // 'A'
startGamePieceLocation.vertLocation = argv[1][1]; // '4' (as char, not int)
// NOTE: this program crashes when no command line argument is passed
// NOTE: this program crashes when first command line arument is a single character
return 0;
}
@JockX
I made it program_name.exe text_file_name.txt startingLocation so argv[2] will be "C:/Users/T_Dub/Desktop/data.txt". What I need to know now is do I put intData.open(argv[2]); or intData.open("argv[2]");
@Matri X
Ahh I think I get it know. Though you have int main(int argc, char** argv) {. When do you need one * and when do you need two?
char** arg is equal to char *arg[]
Now, about arguments, intData.open("argv[2]"); would be wrong, because it would make the open() function search your hdd for file named "argv[2]". You pass variables without quotes.