how do i? re: argc - argv

This is a discussion on how do i? re: argc - argv within the C Programming forums, part of the General Programming Boards category; hello all, im trying to debug a program using Labwindows/CVI (V5.5) IDE running in a dosbox (windows xp). However as ...

  1. #1
    budding software engineer luigi40's Avatar
    Join Date
    Jun 2004
    Location
    South Coast UK
    Posts
    61

    Question how do i? re: argc - argv

    hello all,

    im trying to debug a program using Labwindows/CVI (V5.5) IDE running in a dosbox (windows xp).

    However as the program requires command line parameters i cant see a way to debug the program because CVI doesnt brake on breakpoints when running standalone executable, and when running the program in debug mode one cant fill the argv members, so i thought what about hardcoding the char arrays in global space then passing the arrays to the argv members, but after trying a few different ways i cant get past the compiler.

    can it be done? im not an expert, been programming for a few months now.

    i have been reading around this sight and have learned what argc - argv mean but dont know enough about 'c' to work out a way to do this.

    my program (well most of it belongs to Ray Gardner - Public Domain) is here:
    Code:
    //#include <ansi_c.h>
    #include "scaldate.h"
    
    #if ISO_CAL			/* MONDAY == 0 */
    	#define ADJ 5
    #else 				/* SUNDAY == 0 */
    	#define ADJ 6 
    #endif
    
    unsigned DOW(unsigned y, unsigned m, unsigned d)
    {
    	if (m < 3)
    	{
    		m += 13;
    		y--;
    	}
    	else m++;
    	return (d + 26 * m / 10 + y + y / 4 - y / 100 + y / 400 + ADJ) % 7;
    }
    
    
    
    #include <stdio.h>
    #include <stdlib.h>
        
        
    
    
    /* argc is the number of command line parameters including the name of the 
       program , argv[] is an array of pointers to the command line parameters */
    int main(int argc, char *argv[])
    {
    
    	
    	
    	int ch;
    	int Day;
    	void usage(void);
    	unsigned d, m, y, days[] = {31, 29, 31, 30, 31, 30,
    								31, 31, 30, 31, 30, 31};
    	
    	char *day[2][7] = {{ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"},
    					   { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}};
    						 
    	char *month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
    					 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",};
    	
    					 
    	if (4 > argc)
    		usage();
    	y = atoi(argv[1]);
    	m = atoi(argv[2]);
    	d = atoi(argv[3]);
    	if (!m || m > 12)
    		usage();
    	if (!d || d > days[m - 1])
    		usage();
    	if (y < 100)
    		y += 1900;
    	Day = DOW(y, m, d);
    	printf("DOW(ISO_CAL=%d) returned %d, so %d %s %d is a %s\n",
    		ISO_CAL, Day, d, month[m - 1], y, day[ADJ - 5][Day]);
    	
    	printf ("Press [Enter] to continue");
       while ((ch = getchar()) != '\n' && ch != EOF);
       return(0);
    	
    		
    
    }
    
    
    
    void usage(void)
    {
    	int ch;
    	puts("Usage: DOW yy[yy] mm dd");
        
        printf ("Press [Enter] to continue");
        while ((ch = getchar()) != '\n' && ch != EOF);
    	
    	exit(-1);
    }
    luigi

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,537
    Well in VC++, you do this
    Project->Settings
    Select the debug tab
    fill in the dialog titled "program arguments"

    Might I suggest you ask on the support forum for your IDE if you have an IDE issue.
    Whilst we can easily help you with the 'C' issues, numbers thin rapidly when you start accounting for any number of IDE's
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    If worse comes to worst, you can always use
    Code:
    int
    main(void)
    And then declare argc and argv within main for your testing:
    Code:
    int
    main(void)
    {
      ...
      int   argc = 4;
      char *argv[] = {
        "prog",
        "2004",
        "6",
        "11",
      };
    
      ...
    }
    My best code is written with the delete key.

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, 05:09 AM
  3. Converting a argc / argv construct into a va_list
    By chambece in forum C Programming
    Replies: 6
    Last Post: 07-03-2005, 04:47 PM
  4. argc & argv
    By miryellis in forum C Programming
    Replies: 11
    Last Post: 09-19-2004, 11:59 PM
  5. more argv and argc
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 09-08-2001, 11:04 PM

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