Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ncar!tank!uxc!uxc.cso.uiuc.edu!osiris.cso.uiuc.edu!hood From: hood@osiris.cso.uiuc.edu Newsgroups: comp.lang.c Subject: How big is the argv[] array? Message-ID: <1239500004@osiris.cso.uiuc.edu> Date: 3 Oct 88 17:21:00 GMT Lines: 48 Nf-ID: #N:osiris.cso.uiuc.edu:1239500004:000:1316 Nf-From: osiris.cso.uiuc.edu!hood Oct 3 12:21:00 1988 How big is the argv[] array? Or to ask it another way, how safe is it to go past the argc-1'th element in the argv[] array? Isn't it true that the array of pointers (or pointer to pointers, depending on your point of view) "argv" actually contains argc+1 elements, and not argc elements? Consider the following command line, "command this is a test". Is argv passed to the program like this: argc = 5 argc = 5 argv[0] = command argv[0] = command argv[1] = this argv[1] = this argv[2] = is or is it argv[2] = is argv[3] = a argv[3] = a argv[4] = test argv[4] = test argv[5] = NULL I had read somewhere that argc was not really required to process command line arguments because, you could test for the NULL in the array to signal the end of the arguments. Consider this code fragment where I "walk off the end" of argv[] if argc is equal to 1. Is this guaranteed to work? main(argc, argv) int argc; char *argv[]; { int i; /* fake an argument */ if (argc == 1) { argv[argc] = "dummy"; argc++; } /* process arguments */ for (i=1; i