Thread: argv, taking random char input

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    12

    Question argv, taking random char input

    Hi, how can you pass any char as an argument to a program e.g. $ and simply place it as a char, not a variable.

    Code:
    int main(int argc,char *argv[]) {
    ...

    Here is an example:
    Code:
    ./a.out "x3i0$fe$nk$l1o82wa2#kr0pd5#44le9$g553mf7"
    
    fe: Undefined variable.
    See the problem, it's taking the $fe, as a variable (when it's supposed to simply put each $ f e into my char array), and who knows what other problems could occur, since this is a a massive 700char random string (which I simply trimmed to show as an example to you). How can I input any CHAR as an argument, it must be valid for all common ASCII char 0-127.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I don't have any idea what your question is. For that command line, argv[1] would be "x3i0$fe$nk$llo82wa2#kr0pd5#44le9$g553mf7". What you do with it is up to you.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Try using single quotes to quote the 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

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    12

    Thumbs up

    Quote Originally Posted by laserlight View Post
    Try using single quotes to quote the command line argument.
    Such a simple solution, how did I miss that. Cheers.

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Strangely enough, I’m able to read the command lines with no double quotes, no single quotes, with single quotes and double quotes.

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with taking input from a file
    By babe20042004 in forum C++ Programming
    Replies: 3
    Last Post: 11-16-2009, 08:25 AM
  2. Taking input in C
    By GUIPenguin in forum C Programming
    Replies: 1
    Last Post: 04-12-2006, 01:53 PM
  3. Taking int arguments with char?
    By Munkey01 in forum C++ Programming
    Replies: 2
    Last Post: 01-11-2003, 10:29 PM
  4. Taking input while calculating
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 07-12-2002, 04:47 PM
  5. Taking Voice input
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 01-30-2002, 01:34 PM

Tags for this Thread