hi,
delta error amish.. that should b for char ** arg; but nikhil got char *arg[4]; :-) nikhil.. any other methods .. let us c ... char arg1[BUF_SIZE]; char *arg[4] int i; for(i=0; i<4;i++) arg[i] = &arg1[0]; .. /* oops but i m burying all args in to same grave ;-) */ so .. ... char arg1[BUF_SIZE], arg2[BUF_SIZE], arg3[BUF_SIZE], arg4[BUF_SIZE]; arg[0] = &arg1[0]; arg[1] = &arg1[0]; arg[2] = &arg1[0]; arg[3] = &arg1[0]; ... /* ohh.. that could b painful digging if too many to b buried */ ... char arg1[BUF_SIZE * 4] for(i=0; i<4; i++) arg[i] = &arg1[i * BUF_SIZE]; ... /* gosh.. if u bury anybody longer than BUF_SIZE.. u r tampering others grave */ for(i=0;i<4;i++){ arg[i] = (char *) calloc(BUF_SIZE, sizeof (char)); } /* ok .. looking nice.. but then if i don't clear the grave after buried r (scope)deceased.. my burial ground will b filled too */ #define NO_OF_ARGS char **arg; arg = (char **) calloc (NO_OF_ARGS, sizeof(char *));
for(i=0;i<NO_OF_ARGS; i++){ arg[i] = (char *) calloc (BUF_SIZE, sizeof(char)); } /* ok.. i m digging the burial ground too !*/
caveat: if you dig, remember to cover later (think free!!)
ok.. above is just for fun.. no offence implied. -shailesh
--- Amish Mehta amish@ownmail.com wrote:
Hi,
You got divine hands :-). Though it worked, you should still allocate memory to arg itself for holding array of pointers. Something like
arg = (char **) malloc(sizeof(char *) * 6); arg[5] = NULL;
Amish.
Nikhil Joshi wrote:
Hi!
success afterall ... I used following to allocate memory to arg
for (i=1;i<4;i++) if ((arg[i] = (char *) malloc (30)) == NULL)
__________________________________________________ Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! http://sbc.yahoo.com