Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › C++/C Programming › command-line arguments

command-line arguments

Posts 1–14 of 14 · Page 1 of 1
LA
lalakijilp
command-line arguments
the module 5 mastery check said:

8. Write a program that requires a password that is specified on the command line. Your program doesn’t have to actually do anything except report whether the password was entered correctly or incorrectly.
i forget how it worked so i looked back. after reading that part of the chapter again i still didn't understand it so i made the example program to make it more clear. but the program didn't work. and the last system pause is never executed.

1 can someone explain to me how command-line arguments work and what they do?

2 can someone tell me why the code doesn't work.

the code of the example program that doesn't work:
Code:
#include <iostream>
#include <cstdlib>
using namespace std;

int main(int argc, char *argv[])
{
    double a, b;
    if (argc!=3)
    {
                cout <<"usage: add num num" <<endl;
                system("pause");// added this one so the screen wouldn't disappear
                return 1;
    }
    
    a = atof(argv[1]);
    b = atof(argv[2]);
    
    cout  << a+b;
    
    system("pause");
    return 0;
}
#1 · edited 16y ago · 16y ago
LY
Lynie
Google "How C Programming works" and go the 39th chapter. And don't use System("pause").
#2 · 16y ago
LA
lalakijilp
Quote Originally Posted by Lynie View Post
Google "How C Programming works" and go the 39th chapter. And don't use System("pause").
if i dont use system pause the program will execute and close in a milisec and i will only see a flash...
#3 · 16y ago
B1ackAnge1
B1ackAnge1
Your code works just fine, but you may want to add a '<< endl;' where you print out the numbers.

It's really not that hard;
ARGC has how many arguments there are INCLUDING the exe name.
ARGV holds the strings for these arguments

So if you have 'Add.exe 3 5.4' you'll get
Argc = 3;
and Argv[0] = "Add.exe"
Argv[1] = "3";
Argv[2] = "5.4";

Lynie and a lot of other people hate System("Pause") and would rather have you use getch() or something similar. They have a point -See my post here. Though it seems silly to keep rehashing that same point over and over to people who are just learning. If you have something that works and makes sense to you go with it.. not like any of this is 'commercial grade' software
#4 · edited 16y ago · 16y ago
LY
Lynie
Quote Originally Posted by lalakijilp View Post
if i dont use system pause the program will execute and close in a milisec and i will only see a flash...
Then use another way to wait for key input, such as getchar()
#5 · 16y ago
LA
lalakijilp
Quote Originally Posted by B1ackAnge1 View Post
Your code works just fine, but you may want to add a '<< endl;' where you print out the numbers.

It's really not that hard;
ARGC has how many arguments there are INCLUDING the exe name.
ARGV holds the strings for these arguments

So if you have 'Add.exe 3 5.4' you'll get
Argc = 3;
and Argv[0] = "Add.exe"
Argv[1] = "3";
Argv[2] = "5.4";

Lynie and a lot of other people hate System("Pause") and would rather have you use getch() or something similar. They have a point -See my post here. Though it seems silly to keep rehashing that same point over and over to people who are just learning. If you have something that works and makes sense to you go with it.. not like any of this is 'commercial grade' software
thanks but....

the code probably is right but the program doesnt work.
it looks like the program never gets past the if
#6 · 16y ago
LY
Lynie
Quote Originally Posted by lalakijilp View Post
thanks but....

the code probably is right but the program doesnt work.
it looks like the program never gets past the if
Could you write the output of your program?
#7 · 16y ago
B1ackAnge1
B1ackAnge1
I ran it and it worked.
What are you passing to the command line? If you're running it from within Visual Studio, then you'll have to set the arguments in the project properties.
Right click on the project->Properties,
Then go to "Debug" and you'll see an entry for 'Command Line Arguments"
Where then you'd type : 3 5.4
or whatever numbers you want to pass in

Or you could simply open a dos prompt in the folder where you have your EXE and run it from there (which also negates the need for any of this pause/getch stuff)
#8 · 16y ago
LA
lalakijilp
Quote Originally Posted by B1ackAnge1 View Post
I ran it and it worked.
What are you passing to the command line? If you're running it from within Visual Studio, then you'll have to set the arguments in the project properties.
Right click on the project->Properties,
Then go to "Debug" and you'll see an entry for 'Command Line Arguments"
Where then you'd type : 3 5.4
or whatever numbers you want to pass in

Or you could simply open a dos prompt in the folder where you have your EXE and run it from there (which also negates the need for any of this pause/getch stuff)
i use dev c++ and i didn't "pass" anything to the command line

and how do you pass anything to the command line?
because that is the opdracht en het is niet uitgelegt in de tutorial
#9 · 16y ago
B1ackAnge1
B1ackAnge1
yeah.. what's happening is that it's running the app without anything on the command line so it always gets a argc of 1.

just googled really quickly:
"To pass command-line parameters to your program, go to the "Execute" menu, choose "Parameters" and type in any paramaters you wish to pass."

So there you'd type 2 numbers


or just open a command prompt, cd to the drive\folder where your exe sits and just type it in old-school
add.exe 3 5.4

But most people nowadays don't know how to use a command prompt
#10 · 16y ago
Hell_Demon
Hell_Demon
create a shortcut to the exe and put it behind the path?
#11 · 16y ago
LA
lalakijilp
it works but only if it is executed with dev C++
why is this happening
#12 · 16y ago
B1ackAnge1
B1ackAnge1
If you run it by just double clicking you're again not passing in any arguments thus it will find argc == 1

you have to pass the arguments to it by either
a) Passing them through your Dev environment
b) Do what HD said and make a shortcut and add them there
c) Run the program from the Dos-Prompt (which you should learn since
most of these apps you're writing are really made to be ran like that anyway).
#13 · 16y ago
LA
lalakijilp
thanks it worked
#14 · 16y ago
Posts 1–14 of 14 · Page 1 of 1

Post a Reply

Similar Threads

  • Start a program with command line args [solved]By Kudi in Visual Basic Programming
    3Last post 15y ago
  • Starting Minecraft Command-Line!By hexacyanide in Minecraft Discussions
    2Last post 15y ago
  • Command line parametersBy m0k1 in Combat Arms Coding Help & Discussion
    0Last post 15y ago
  • Interfacing with Command-Line programs.By Jason in Visual Basic Programming
    4Last post 15y ago
  • [Tutorial] Reading from the CMD lineBy shercipher in C++/C Programming
    7Last post 20y ago

Tags for this Thread

#arguments#commandline