Thread: argv

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    270

    argv

    hi im trying the following pseudocode:

    Code:
    Algorithm image
    CHARACTER cla
    
    output 'Welcome to my program'
    input argv[count]
    	
    	if argv = -i
    		output 'You have decided to invert the image'
    		..CALL FUNCTION..
    	elseif argv = -h
    		output 'You have decided to scroll the image'
    		..CALL FUNCTION..
    	else 
    		output 'ERROR: Incorrect argument'
    		return 0
    	endif
    end algorithm
    do i need a for loop for it?
    Now for argv does it seem right? like will it perform what iv asked?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    do i need a for loop for it?
    Why would you need a loop? Also, what is argv? If it refers to the command line arguments, then "input argv[count]" is rather unnecessary.

    Now for argv does it seem right? like will it perform what iv asked?
    Yes, of course, if you are able to correctly translate the pseudocode into code.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    ok cool, but what if i was to enter 2 arguments like:
    a.out -i 45

    wont i need an array for that then or how to i deal with it to use the -i and then be able to use the 45 somewhere as well?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You might want to brush up your knowledge of command line arguments by reading cprogramming.com's tutorial on Accepting command line arguments.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    so basically each CLA is a position, so a.out is at 0, so -1 is at 1, 45 is at 2? am i correct

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Yes, though in your example it is -i, not -1, that is at position 1.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    oh yea sorry wrong input, thanks

  8. #8
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    i am totally confused on how to get an image into an array, i got the following library:

    Code:
    // This must be called before you start using the library of routines
    void ep100_lib_init();
    
    //  This routine will open the image whose full path is specified as a parameter
    //  It will return a 1 on error (probably cannot open file) and a 0 on success
    int ep100_lib_open_image(char * filename);
    
    // This function returns the width in pixels of the loaded image.
    int ep100_lib_get_image_width();
    
    // This function returns the height in pixels of the loaded image.
    int ep100_lib_get_image_height();
    
    // This routine will put the image pixel data into the supplied matrix
    // from top left to bottom right. You must ensure that enough space is
    // available.
    void ep100_lib_get_data(int data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y]);
    
    // This routine will set the image pixel data from the supplied matrix
    // from top left to bottom right. You must ensure that enough space is
    // available.
    void ep100_lib_set_data(int data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y])
    Now how do i put the image in an array.
    is it:

    int array[data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y]]?


    OR is it

    int array[ep100_lib_get_data(data)]?
    Last edited by taurus; 10-14-2007 at 08:01 AM.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What kind of data type would you call this:
    Code:
    int data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y];
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    2-D array?

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    correct. So how do you think you should use a function that takes this 2D array as a parameterl?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    int array[EP100_LIB_MAX_X][EP100_LIB_MAX_Y]

    but that doesnt set up a 2d array with the pixels or does it?

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It sets up a 2D array - no, the array doesn't automatically contain pixels (or anything else for that matter). Isn't that what those functions are for?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    Registered User
    Join Date
    Aug 2007
    Posts
    270

    ok here

    ok could someone please have a look at this pseudocode i developed and comment on it:

    Code:
    Algorithm image
    
    ep100lib.h
    
    INTEGER width
    INTEGER height
    DOUBLE scroll
    CHARACTER filename <-- NULL
    output 'Welcome to my program'
    
    	if argv[1] = -i
    		output 'You have decided to invert the image'
    		..CALL FUNCTION..
    
    	elseif argv[1] = -h
    		scroll <-- argv[2]
    		filename <-- argv[3]
    
    		ep100_lib_init()
    		ep100_lib_open_image(filename)
    
    		INTEGER data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y]
    		ep100_lib_get_data(data)
    
    		width <-- ep100_lib_get_image_width()
    		height <-- ep100_lib_get_image_height()
    
    		output 'You have decided to scroll the image'
    		
    		
    		scroll_image_procedure(data,scroll)
    
    		
    	elseif argv[1] = -v
    		DOUBLE scroll <-- argv[2]
    		output 'You have decided to scroll the image'
    		..CALL FUNCTION..
    
    	else 
    		output 'ERROR: Incorrect argument'
    		return 0
    	endif
    end algorithm
    and the procedure:

    Code:
    void scroll_image_procedure(int data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y], 						double scroll)
    
    		INTEGER x
    		for(x <-- 0 to Ep100_LIB_MAX_X)
    			data[X+scroll] = data
    thanks

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    When you scroll the image, how do you plan on dealing with "what's falling over the edge"? Does the image grow, or are you wrapping it around the end to the other side? Or is the scrolled image guaranteed to fit in the new data?

    Also, are you allowed to scroll in multiple directions (horizontal, vertical, positive and negative amounts?)

    All of the above should be covered in your requirements, or you can't really implement the function - but maybe you are allowed to interpret it as you like? If so, which are you trying to implement?

    You scroll function probably should only scroll the ACTUAL width/height of the image, rather than the entire image size (assuming that is not the same thing - which I think it isn't, but again, I don't know).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help getting a grib on argc and argv
    By elwad in forum C Programming
    Replies: 10
    Last Post: 05-01-2009, 10:13 AM
  2. Using argc and argv data
    By Rad_Turnip in forum C Programming
    Replies: 4
    Last Post: 03-31-2006, 06:09 AM
  3. how do i? re: argc - argv
    By luigi40 in forum C Programming
    Replies: 2
    Last Post: 06-11-2004, 10:17 AM
  4. Argv And Argc
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 12-11-2001, 03:43 PM
  5. more argv and argc
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 09-08-2001, 11:04 PM