On 26 Sep 2002, Mandar Khanolkar wrote:
Allocate memory for arg[] before gets(). Use malloc().
thx guys 4 the suggestions. i've added the following code : But still i get the same error (Segmentation Fault) Also curious: How come the program runs perfectly in DOS without allocating memory ?
/* Now Allocate memory for arg[4] I dunno why the following doesn't work:
if ((arg = (char *) malloc (30)) == NULL)
Compiler gives the error: incompatible types in assignment
Is there some other method to allocate memory to array of pointers? */
if ((*arg = (char *) malloc (30)) == NULL)
{ printf ("Error allocating memory \n"); exit (1); }
P.S. I know this is not the right place to discuss C programming but guys pls bear with me ...
-- Nikhil Joshi