ashley maher wrote:

try this instead:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int somefunction(char **string1)
{
       char *string2 = "some words\0";

       *string1 = (char *)calloc(strlen(string2 + 1), sizeof (char));

       strcpy(*string1, string2);

       return 0;
}


int main ()
{
       char *string;

       somefunction(&string);

       printf ("\n\nString is: %s\n\n", string);

       free (string);

       return 0;
}

I presume this is for some school assignment, in which case you should study more.

If not, you should be aware there is a function called strdup() which does this.

Trent
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to