about commandline arguments

This is a discussion on about commandline arguments within the C Programming forums, part of the General Programming Boards category; Hi fellows, I have little program here that I want to incorprate some more commandline arguments and it would be ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    28

    about commandline arguments

    Hi fellows,

    I have little program here that I want to incorprate some more
    commandline arguments and it would be run this way:

    <proramname> rounds FFFFF ENC < fileIn > fileOut
    -------- ------- -----

    rounds = number of rounds in a loop
    FFFFFF = hex value used as key
    ENC = means to be encrypted

    the underlined args are the new ones and also would like to
    use in loop as stopping condition.

    can anyone tell me how can incoorprate the 3 more args ?

    thanks in advance.

    here is tha program:

    Code:
    code
    
    /* Function: Open files */
    bool open_files (FILE *infile, FILE *outfile)
    {
        
        bool retval;
        
        infile = fopen ("test.txt", "r");
        outfile = fopen ("res.txt", "w");
        
        if (infile == NULL || outfile == NULL)
        {
            close_files (infile, outfile);
            retval = false;
        }
        else
        {
            retval = true;
        }
        
        return retval;
    }

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > can anyone tell me how can incoorprate the 3 more args ?
    I'd love to help, but it seems as if I am only presented with a file manipulating function that accepts file input & output.

    I don't see any attempt at your command line parameter section, or even the general area of the code where it's at.

    Do a search for command line arguments through these baords.
    The world is waiting. I must leave you now.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    > can anyone tell me how can incoorprate the 3 more args
    Since your program had no arguments to start with....

    proramname < fileIn > fileOut
    Has no arguments, it has redirections which are managed by the shell, and your program just deals with stdin and stdout

    Simple args code
    Code:
    int main ( int argc, char *argv[] ) {
      int i;
      for ( i = 0 ; i < argc ; i++ ) {
        printf( "Arg %d is %s\n", i, argv[i] );
      }
      return 0;
    }
    Once you know where/how "rounds FFFFF ENC" appear, you should be able to figure out how to use them

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 04:27 PM
  2. command line arguments
    By vurentjie in forum C Programming
    Replies: 3
    Last Post: 06-22-2008, 07:46 AM
  3. Replies: 10
    Last Post: 09-27-2005, 01:49 PM
  4. NULL arguments in a shell program
    By gregulator in forum C Programming
    Replies: 4
    Last Post: 04-15-2004, 11:48 AM
  5. my own commandline parser function
    By scrappy in forum C Programming
    Replies: 7
    Last Post: 08-22-2003, 03:57 AM

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