Like Tree1Likes

Command line arguments

This is a discussion on Command line arguments within the C++ Programming forums, part of the General Programming Boards category; HOW TO ENTER SUCH COMMAND LINE ARGUMENTS AND USE IN C++ C:\> ewb11 <enter> EWB11:\> circuit cir1 <enter> n, N1, ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    7

    Exclamation Command line arguments

    HOW TO ENTER SUCH COMMAND LINE ARGUMENTS AND USE IN C++

    C:\> ewb11 <enter>
    EWB11:\> circuit cir1 <enter>
    n, N1, N2
    cs, U1, 10m, N2 to N1 <enter>
    r, R1, 3k, N1 to N2 <enter>
    r, R2, 3000, N1 to N2 <enter>
    r, R3, 0.003M, N1 to N2 <enter>
    o, Vt, N1 to N2
    done <enter>

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    How to use Google??????
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    7
    SIR CAN YOU HELP I TRIED ALOT but i didn't understood

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,598
    Do you have any clue as to what is a command line argument?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Apr 2012
    Posts
    7
    yes int main ( int argc, char *argv[] )
    argc = number of commands and argv[] give access to a particular command.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,598
    So, what don't you understand?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Apr 2012
    Posts
    7
    for the program i run the exe file i just enter the exe location and when i press enter th program executes and I am not able to pass command lines repeatedly

    such as

    circuit cir1 <enter>
    n, N1, N2
    cs, U1, 10m, N2 to N1 <enter>
    r, R1, 3k, N1 to N2 <enter>
    r, R2, 3000, N1 to N2 <enter>
    r, R3, 0.003M, N1 to N2 <enter>
    o, Vt, N1 to N2
    done <enter>

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,598
    Oh. In that case, it sounds like you want to read from standard input until a special input is detected rather than process command line arguments.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Apr 2012
    Posts
    7
    What do u mean by this

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,598
    For example:
    Code:
    std::string line;
    while (std::getline(std::cout, line) && line != "done")
    {
        // Process the line
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Registered User
    Join Date
    Apr 2012
    Posts
    7
    which header file needs to be included?

  12. #12
    Registered User
    Join Date
    Apr 2012
    Posts
    7
    which header file needs to be included for this as it is giving error

  13. #13
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by laserlight View Post
    Oh. In that case, it sounds like you want to read from standard input until a special input is detected rather than process command line arguments.
    If the program name is "circuit" then his example looks like a combination, reading (presumably) the name of the circuit as a command-line argument and the rest from stdin.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  14. #14
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    > which header file needs to be included for this as it is giving error
    Post your error message(s).

    Also, tell us which OS and compiler you're using (including version numbers).

    Though somehow I suspect "TurboC" is about to be mentioned....
    inequity likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  15. #15
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    Code:
    C:\> ewb11 <enter>
    EWB11:\> circuit cir1 <enter>
    This is looking like he wants to run a shell-type system. Note the different prompt.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Command Line arguments
    By sidhuram in forum Windows Programming
    Replies: 2
    Last Post: 09-06-2010, 08:49 AM
  2. [C++] Command Line Arguments help
    By camelCase in forum C++ Programming
    Replies: 10
    Last Post: 07-03-2010, 08:18 AM
  3. Command line arguments
    By malooch in forum C++ Programming
    Replies: 3
    Last Post: 12-18-2006, 11:36 PM
  4. Command Line Arguments???
    By luckygold6 in forum C++ Programming
    Replies: 8
    Last Post: 04-28-2003, 05:51 PM
  5. command line arguments
    By zbap in forum C++ Programming
    Replies: 1
    Last Post: 03-13-2002, 10:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21