getting the line from the console

This is a discussion on getting the line from the console within the C Programming forums, part of the General Programming Boards category; basically I'm trying to figure this out. when you do myprog text1 usually in the argv[1] = "text1; or at ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    192

    getting the line from the console

    basically I'm trying to figure this out. when you do

    myprog text1

    usually in the argv[1] = "text1; or at least points to it but if i do

    myprog < text1

    there isnt any argv[1] to get "text1" so is there a way to get that string of characters for "text1" when Im redirecting on the console line.

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    57
    you can use this way myporg <<< "text1"
    It will pass the text1 string to that program as a input.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    192
    Well im required to use it with 1 < redirection so is there any other suggestions

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    57
    Do you want redirection symbol as the input of your program.
    Ex:
    myprog \< text1
    argv[1]="<"
    argv[2]="text1"

    If I understood wrongly correct me
    Last edited by sganesh; 03-03-2010 at 12:42 AM.

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    66
    redirection (< , >) , pipes ( | ) and all the way of input and output designed by the terminal itself for making easy the input and
    output operation, C cannot do any thing in that, so we cannot get the "<filename " in argv ,
    not only in argv but any other way in C.
    Last edited by Alexander jack; 03-03-2010 at 12:46 AM.

  6. #6
    Registered User
    Join Date
    Apr 2009
    Posts
    66

    Thumbs up

    If you want to pass the command line value as < filename ( normal input with out redirection )
    then you can use double quotes or escape character

    for ex :
    $ a.out "<" filename # this cannot redirect the file but take the "< filename " as pure strings
    or
    $ a.out \< filename # this cannot redirect the file but take the "< filename " as pure strings

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by kiros88 View Post
    basically I'm trying to figure this out. when you do

    myprog text1

    usually in the argv[1] = "text1; or at least points to it but if i do

    myprog < text1

    there isnt any argv[1] to get "text1" so is there a way to get that string of characters for "text1" when Im redirecting on the console line.
    myprog < text1 will redirect a file called text1 to stdin of myprog.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Move the Caret to a line
    By TheDan in forum Windows Programming
    Replies: 3
    Last Post: 08-07-2005, 01:59 PM
  2. if is faster than switch?
    By skorman00 in forum C++ Programming
    Replies: 32
    Last Post: 03-06-2004, 01:15 PM
  3. How to Input without Breaking line in a console?
    By Aidman in forum C++ Programming
    Replies: 11
    Last Post: 03-12-2003, 11:55 AM
  4. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 04:53 PM
  5. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 06:21 PM

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