Re: how this works ?



lector wrote:


void create_link_list(node *root, int n)
{
node *p, *prev;
int i;

for(i=0; i<n; i++)
{
p = malloc(sizeof(node));
p->next = NULL;
printf("Enter data\n");
scanf("%d", &p->data);
if(root == NULL)
{
root = p;
prev = root;
}
else
{
prev->next = p;
prev = p;
}
}
}

The program compile successfuly and I could link all the obj files
without any errors or warnings. When I execute the
application(ll.exe), I can input all the numbers but the link list is
not printed. I think the problem lies in the fact that the link list
has been created but the copy of updated pointer to the root node is
not available as it got destroyed once the create routine terminated.

I didn't get destroyed, it got lost. See the FAQs:

<http://c-faq.com/ptrs/passptrinit.html>



Brian
.



Relevant Pages

  • Re: Split or Irreducible
    ... If u is a root for f, ... what I accept as reality." ... Arturo Magidin ... Prev by Date: ...
    (sci.math)
  • Re: how this works ?
    ... void create_link_list(node *root, int n) ... node *p, *prev; ... has been created but the copy of updated pointer to the root node is ...
    (comp.lang.c)
  • Re: multiple-value-bind only accepts symbols
    ... "Premature profiling is the root of all evil." ... Prev by Date: ...
    (comp.lang.lisp)
  • Re: winspire
    ... Linspires default ' user' mode to be if not root? ... DAve ... Prev by Date: ...
    (comp.os.linux.hardware)
  • Re: ImportError: No module name MySQLdb
    ... I installed and am trying to run everything as root, ... help me to get Zope running, it is not cooperating either... ... Prev by Date: ...
    (comp.lang.python)

Loading