Thread: reading input from command line

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    38

    reading input from command line

    hello,

    i just wanted to know if using the getline function is valid to read an input from the command line? also for this specific function do we have to use character pointers or can we use an char array??

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    There is no standard getline function, though there is a POSIX standard getline, so you need to clarify what you are talking about.
    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

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by ueg1990 View Post
    hello,

    i just wanted to know if using the getline function is valid to read an input from the command line? also for this specific function do we have to use character pointers or can we use an char array??
    getline isn't standard C although it is available via GCC. For standard C see How to get a line of text FAQ. For GCC getline see GNU Getline Tutorial.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  4. #4
    Registered User
    Join Date
    Jan 2012
    Posts
    38
    i have to implement a shell, so i have to read inputs entered by the user? is it ok to use getline()??

  5. #5
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    getline is not standard C so it is not guaranteed to work across all implementations. Click on the red things in my post above, they will provide you with the information you are looking for.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading Input from a file, line-by-line
    By Acolyte in forum C Programming
    Replies: 8
    Last Post: 09-30-2007, 01:03 PM
  2. Command Line User Input
    By Matt3000 in forum C++ Programming
    Replies: 1
    Last Post: 09-29-2006, 11:47 AM
  3. Command line input
    By Moony in forum C Programming
    Replies: 9
    Last Post: 07-22-2006, 03:08 AM
  4. Input in Command Line Parameters
    By BianConiglio in forum C Programming
    Replies: 2
    Last Post: 05-02-2004, 05:57 PM
  5. command line input problem
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 12-24-2001, 09:36 PM