Thread: Command line arguments and arrays

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    15

    Command line arguments and arrays

    I need to make a 2-D array based on command line argumnets.

    The program is supposed to compress an image in raw format. The command line is: compress filename width height

    I have:
    Code:
    int main (int argc, char* argv[]){
    
            int width, height;
            FILE* fp;
            char image[][];
    
            if(argc != 4) message();
            width = atoi(argv[2]);
            height = atoi(argv[3]);
    
            
            return(0);
    }
    How can I set the width and height of the image array?
    Any help would be appreciated and I hope I'm not just being stupid. Thanks.

    Oh, and one more question while I'm here:
    How can I modify values bit-by-bit. Thanks again
    Last edited by fatinez; 09-12-2003 at 02:24 PM.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>How can I set the width and height of the image array?
    Use malloc(). There are plenty of examples of malloc'ing 2-d arrays on here, try searching and see what you find.

    >>How can I modify values bit-by-bit.
    Bit manipulation is in the FAQ.

    >>width = atoi(argv[2]);
    If this fails 'cos the user entered a non-number, it will return 0. You'll need to check for that before calling malloc. Better still, use strtol() which allows you to validate the conversion.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    15
    Thanks, I'll see what I can come up with.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arrays as function arguments :(
    By strokebow in forum C Programming
    Replies: 10
    Last Post: 11-18-2006, 03:26 PM
  2. Arrays as function arguments!
    By strokebow in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 02:32 PM
  3. dynamic multidimensional arrays as function arguments
    By magda_k in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2006, 04:00 PM
  4. multidimensional arrays as arguments
    By mrbiggs in forum C++ Programming
    Replies: 13
    Last Post: 12-31-2003, 08:33 AM
  5. Arrays..and arguments
    By fanaonc in forum C Programming
    Replies: 2
    Last Post: 10-16-2001, 04:58 PM