Thread: Command line argument question

  1. #1
    Learner Axel's Avatar
    Join Date
    Aug 2005
    Posts
    335

    Command line argument question

    I'm having trouble getting a reference to the WHOLE character that is passed through command line. Since argv's is made out of chars, i can't seem to get a get the whole string so i can further manipulate it using fopen.

    If i have the following:

    Code:
    int main(int argc, char *argv[])
    i can just print is using

    Code:
    printf("%s", argv[1])
    This is self explanatory , simply because "%s" joins the chars of argv.

    Which works fine....
    However if i use:

    Code:
    File = fopen ( argv[1] , "r" );
    The first character (i.e. if i enter filename, f is passed to fopen).

    So my question is how do i create a char that contains the whole passed in argument?

  2. #2
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Not so, in the above fopen call, the whole string of argv[1] is passed.

  3. #3
    Learner Axel's Avatar
    Join Date
    Aug 2005
    Posts
    335
    essentially, fopen accepts a char as a parameter (from what i read)
    so if i do: printf("\n%c", argv[1]);

    It's basically the same thing as the fopen call therefore it just prints out the first character

  4. #4
    Learner Axel's Avatar
    Join Date
    Aug 2005
    Posts
    335
    hmm never mind.

  5. #5
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    No, fopen accepts a char pointer to a null terminated string. Why would fopen accept a single character for a filename?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function passing argument..array ?
    By jochen in forum C Programming
    Replies: 2
    Last Post: 09-30-2007, 11:53 AM
  2. A stupid question...probably
    By Phoenix_Rebirth in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2007, 04:53 PM
  3. question about linklist
    By fj8283888 in forum C Programming
    Replies: 1
    Last Post: 04-14-2004, 06:13 AM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM