Command line argument question

This is a discussion on Command line argument question within the C Programming forums, part of the General Programming Boards category; I'm having trouble getting a reference to the WHOLE character that is passed through command line. Since argv's is made ...

  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
    cwr
    cwr is offline
    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
    cwr
    cwr is offline
    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, 12:53 PM
  2. A stupid question...probably
    By Phoenix_Rebirth in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2007, 05:53 PM
  3. question about linklist
    By fj8283888 in forum C Programming
    Replies: 1
    Last Post: 04-14-2004, 07:13 AM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM

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