Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8571617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:49:14+00:00 2026-06-11T18:49:14+00:00

I have the next code : #include CmdLine.h void main(int argc, TCHAR **argv) {

  • 0

I have the next code :

#include "CmdLine.h"

void main(int argc, TCHAR **argv)
{

  CCmdLine cmdLine;



  // parse argc,argv 
  if (cmdLine.SplitLine(argc, argv) < 1)
  {
     // no switches were given on the command line, abort
     ASSERT(0);
     exit(-1);
  }

  // test for the 'help' case
  if (cmdLine.HasSwitch("-h"))
  {
     show_help();
     exit(0);
  }

  // get the required arguments
  StringType p1_1, p1_2, p2_1;
  try
  {  
     // if any of these fail, we'll end up in the catch() block
     p1_1 = cmdLine.GetArgument("-p1", 0);
     p1_2 = cmdLine.GetArgument("-p1", 1);
     p2_1 = cmdLine.GetArgument("-p2", 0);

  }
  catch (...)
  {
     // one of the required arguments was missing, abort
     ASSERT(0);
     exit(-1);
  }

  // get the optional parameters

  // convert to an int, default to '100'
  int iOpt1Val =    atoi(cmdLine.GetSafeArgument("-opt1", 0, 100));

  // since opt2 has no arguments, just test for the presence of
  // the '-opt2' switch
  bool bOptVal2 =   cmdLine.HasSwitch("-opt2");

  .... and so on....

}

I have the CCmdLine class implemented and this main is an exemple of how to use it .
I am having difficulties understanding how i get input values . I have tried to read them with scanf from the console but the argc won’t increment and results faulty reading.

I am a beginner in c++ and i would like to know who to make this code work .

Thanks .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:49:15+00:00Added an answer on June 11, 2026 at 6:49 pm

    Argc and argv only contain the arguments that were passed when the program started. So if you execute it with myapp.exe option1 option2 option3, than in your argv you will have:

    • myapp.exe //<--argv[0]
    • option1 //<--argv[1]
    • option2 //<--argv[2]
    • option3 //<--argv[3]

    In a nutshell, when a program starts, the arguments to main are initialized to meet the following conditions:

    • argc is greater than zero.
    • argv[argc] is a null pointer.
    • argv[0] through to argv[argc-1] are pointers to strings representing the actual arguments.
    • argv[0] will be a string containing the program’s name or a null string if that is not available. Remaining elements of argv represent the arguments supplied to the program.

    You can find some more information for example here.

    All attempts to read input later (either with cin, scanf or whatever else) will not save the inputed values to argv, you will need to handle the input yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the next code: #include <stdio.h> int main(void) { int c; while ((c=getchar())!= EOF)
I have this code: #include <stdio.h> int getAns(void); int num; int main() { int
I have next code: int main() { OwnSelect(23, FD_READ | FD_WRITE); // <---- Several
I have to translate this C code to assembly code: #include <stdio.h> int main(){
I have the next C code: #include <stdio.h> #include <stdlib.h> #include list.h #include graph.h
I have next code: #include <iostream> #include <algorithm> #include <map> #include <iterator> //namespace std
I have next code, <form id=form1 runat=server> <asp:Label runat=server ID=Label1 EnableViewState=false /> <asp:CheckBox runat=server
I have next code require 'rack/rpc' class Server < Rack::RPC::Server def hello_world Hello, world!
I have the next code: class Printer{ Activity activity; public Printer (Activity activity) {
I have the next code : public class AddPrinter extends ListActivity { @Override public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.