an*******@yahoo.com said:
On May 12, 12:40 am, anand1...@yahoo.com wrote:
>hi,
Following is problematic Code
main()
{
char *ptr[1]={NULL};
ftn(ptr);
printf("String is %s\n",*ptr)
/*It PRints "HAI" -No Problem*/
if(*ptr !=NULL)
free(*ptr);
/*It Says Invalid Pointer*/
>}
void ftn(**data)
{
*data=malloc(4);
memset(*data,0,4);
strcpy(*data,"HAI");
}-
hi,
Please let me why the free is throwing "Inavild Pointer" Error.
foo.c:2: warning: return-type defaults to `int'
foo.c:2: warning: function declaration isn't a prototype
foo.c: In function `main':
foo.c:3: `NULL' undeclared (first use in this function)
foo.c:3: (Each undeclared identifier is reported only once
foo.c:3: for each function it appears in.)
foo.c:3: initializer element is not computable at load time
foo.c:3: (near initialization for `ptr[0]')
foo.c:4: warning: implicit declaration of function `ftn'
foo.c:5: warning: implicit declaration of function `printf'
foo.c:7: parse error before `if'
foo.c:10: warning: control reaches end of non-void function
foo.c: At top level:
foo.c:12: parse error before `*'
foo.c:13: warning: function declaration isn't a prototype
foo.c:13: warning: type mismatch with previous implicit declaration
foo.c:4: warning: previous implicit declaration of `ftn'
foo.c:13: warning: `ftn' was previously implicitly declared to return
`int'
foo.c: In function `ftn':
foo.c:14: `data' undeclared (first use in this function)
foo.c:14: warning: implicit declaration of function `malloc'
make: *** [foo.o] Error 1
Sort those out, and come on back if you're still having trouble.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.