Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Main Arguments

Main Arguments

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheDelChop
    wrote on last edited by
    #1

    Hi guys, I am writing a simple program that the user would like to be able to run from the command prompt. I am wondering how I pass that infromation into the main of my program. For example, if you wish to run Windows explorer from the command line you pass the command "explorer". This will launch Windows explorer and default to showing C:\. However, you can also call explorer and have it open a specific directory "explorer C:\Test\MyTest". My question is this: Is the second part of that simply passed as the argument to main? For example if I wanted my program to specify a string, could I have my main function accept a const char *? I.E. void main(const char *inputString) ? where inputString would be whatever it is that I have passed immediately after my *.exe name? so the total call would be something like: C:\> stringParser This Is My Test which would hopefully pass a pointer to "This is My Test" into my main argument. Thanks, Joe

    M T 2 Replies Last reply
    0
    • T TheDelChop

      Hi guys, I am writing a simple program that the user would like to be able to run from the command prompt. I am wondering how I pass that infromation into the main of my program. For example, if you wish to run Windows explorer from the command line you pass the command "explorer". This will launch Windows explorer and default to showing C:\. However, you can also call explorer and have it open a specific directory "explorer C:\Test\MyTest". My question is this: Is the second part of that simply passed as the argument to main? For example if I wanted my program to specify a string, could I have my main function accept a const char *? I.E. void main(const char *inputString) ? where inputString would be whatever it is that I have passed immediately after my *.exe name? so the total call would be something like: C:\> stringParser This Is My Test which would hopefully pass a pointer to "This is My Test" into my main argument. Thanks, Joe

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      In Visual C++, you can use the version of _tmain that has command line argument parameters: int _tmain(int argc, _TCHAR* argv[]) See main: Program Startup[^] Mark

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

      T 1 Reply Last reply
      0
      • M Mark Salsbery

        In Visual C++, you can use the version of _tmain that has command line argument parameters: int _tmain(int argc, _TCHAR* argv[]) See main: Program Startup[^] Mark

        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        Mark Salsbery wrote:

        int _tmain(int argc, _TCHAR* argv[])

        strange from microsoft that argv is not an array of **const** TCHAR* :|


        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        M 1 Reply Last reply
        0
        • T toxcct

          Mark Salsbery wrote:

          int _tmain(int argc, _TCHAR* argv[])

          strange from microsoft that argv is not an array of **const** TCHAR* :|


          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          toxcct wrote:

          strange from microsoft that argv is not an array of const TCHAR*

          Yeah. I guess it stays consistent with the old days of C :) There's no const in any of the prototype variations. Beats me! Mark

          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

          1 Reply Last reply
          0
          • T TheDelChop

            Hi guys, I am writing a simple program that the user would like to be able to run from the command prompt. I am wondering how I pass that infromation into the main of my program. For example, if you wish to run Windows explorer from the command line you pass the command "explorer". This will launch Windows explorer and default to showing C:\. However, you can also call explorer and have it open a specific directory "explorer C:\Test\MyTest". My question is this: Is the second part of that simply passed as the argument to main? For example if I wanted my program to specify a string, could I have my main function accept a const char *? I.E. void main(const char *inputString) ? where inputString would be whatever it is that I have passed immediately after my *.exe name? so the total call would be something like: C:\> stringParser This Is My Test which would hopefully pass a pointer to "This is My Test" into my main argument. Thanks, Joe

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #5

            if you somehow graduate to windows programming you can use GetCommandline api to reterive the command line

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups