Thread: Command line arguments

  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
    28,413
    Do you have any clue as to what is a command line argument?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    So, what don't you understand?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    For example:
    Code:
    std::string line;
    while (std::getline(std::cout, line) && line != "done")
    {
        // Process the line
    }
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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....
    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.

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

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-19-2006, 12:36 AM
  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, 11:29 AM