Thread: Reading operands

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    14

    Reading operands

    How do you read the string typed after the command in the terminal? For example, to open the page "http://cboard.cprogramming.com/", you could type into the terminal:

    $ firefox http://cboard.cprogramming.com/

    In standard sequential C, how do you get the program to read the operand?

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Code:
    #include <stdio.h>
    int main(int argc, char *argv[])
    {
        if (argc > 1)
        {
            const char *firstArgument = argv[1];
            printf("First argument: %s\n", firstArgument);
        }
        return 0;
    }
    Last edited by rags_to_riches; 02-17-2008 at 10:48 PM. Reason: Error checking :)

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    14

    Thumbs up

    Thank you very much, I thought it would be something like that, but I was not sure.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2009, 03:14 AM
  2. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  3. Replies: 2
    Last Post: 01-28-2008, 03:07 AM
  4. Problems in reading binary file
    By serena in forum C Programming
    Replies: 3
    Last Post: 04-14-2005, 03:54 AM
  5. Need help with C program
    By ChrisH in forum C Programming
    Replies: 38
    Last Post: 11-13-2004, 01:11 AM