Thread: variable

  1. #1
    Registered User
    Join Date
    Feb 2010

    Question variable

    I was trying to get my program to work the following way from the terminal (command prompt):

    a.out 20 < document.doc

    where the value "20" (or whatever is typed) is used as a variable in the compiled program's a.out file (program.cpp). I've tried a bunch of different ways to no avail... Help?
    Last edited by bond_006; 04-11-2010 at 08:10 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    I don't think that makes any sense as you have it typed. You have a compiled program, yes? Does it take a command-line argument? If so, just type it: "a.out 20". If it doesn't take a command-line argument, then you've already lost ... unless it takes input from the user, in which case you need a file that says 20 in it that you can use to redirect (although just waiting to type "20" at the prompt doesn't seem like such a burden).

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If the program is expecting an integer (on stdin), followed by a document (also on stdin), then do this:
    ( echo "20" ; cat document.doc ) | a.out
    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.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Salem's bash code is probably not what you want, in all likely hood.

    How does the program read in 20 and the doc file?
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  2. Use of variable
    By alice in forum C Programming
    Replies: 8
    Last Post: 06-05-2004, 07:32 AM
  3. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  4. write Variable and open Variable and get Information
    By cyberbjorn in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 01:30 AM
  5. Variable question I can't find answer to
    By joelmon in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2002, 04:11 AM