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 parameters.........

main parameters.........

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 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.
  • J Offline
    J Offline
    Jay03
    wrote on last edited by
    #1

    Hey guys, I was wondering when we use these parameters (int argc, char *argv[]) in a main function? I have no clue why they use it.... Thanks in advance void main (int argc, char *argv[]) { .......... ......... }

    Z J D 3 Replies Last reply
    0
    • J Jay03

      Hey guys, I was wondering when we use these parameters (int argc, char *argv[]) in a main function? I have no clue why they use it.... Thanks in advance void main (int argc, char *argv[]) { .......... ......... }

      Z Offline
      Z Offline
      Zac Howland
      wrote on last edited by
      #2

      They are used for command line parameters. argc tells you how many elements are in the argv array. argv holds the space-delimited strings. Say you write a program that will write out a given string X number of times and you want to allow the user to determine what the string is and how many times by passing in command line parameters: MyEcho.exe 5 Hello! argc would be 3 (1 for the module name, and then the parameters). argv would hold the parameters to parse for the program.

      If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

      1 Reply Last reply
      0
      • J Jay03

        Hey guys, I was wondering when we use these parameters (int argc, char *argv[]) in a main function? I have no clue why they use it.... Thanks in advance void main (int argc, char *argv[]) { .......... ......... }

        J Offline
        J Offline
        Jun Du
        wrote on last edited by
        #3

        For command line arguments. Basically, if you have an executable named "app.exe" and you a the command line like this: app.exe your_arg1 your_arg2 then argc is 3, argv[1] is "your_arg1" and argv[2] is "your_arg2". Note that argv[0] is always "app.exe".

        Best, Jun

        1 Reply Last reply
        0
        • J Jay03

          Hey guys, I was wondering when we use these parameters (int argc, char *argv[]) in a main function? I have no clue why they use it.... Thanks in advance void main (int argc, char *argv[]) { .......... ......... }

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          See here.


          "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

          "Judge not by the eye but by the heart." - Native American Proverb

          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