Question about list (struct {..struct *next}

This is a discussion on Question about list (struct {..struct *next} within the C Programming forums, part of the General Programming Boards category; Hi all, i hope you can help me understand why this acts like this, im putting here just one function ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    4

    Post Question about list (struct {..struct *next}

    Hi all, i hope you can help me understand why this acts like this, im putting here just one function but if you want to see the full file is here http://www10.brinkster.com/jmzl666/nodes.txt (is a txt just rename it to .c). first of all im working with turbo c++ 3 (i know is old but i cant afford a new compiler) and windows xp pro, wel, the problem is that i have a structure like this
    <code>
    struct node{
    int info;
    struct node *next;
    };
    typedef struct node *nodoaptr;
    //decalre this inside the main
    nodoaptr p=NULL;
    </code>
    i try to make a list using malloc, everything works fine but i have a question (silly if you want), as you see the nodoaptr type is a pointer, so i supose it can be modified enywhere, but it doesnt, here is the original function to create a node (basic version)

    <code>
    void insnodo(nodoaptr *plist,int x)
    {
    nodoaptr q,w;
    //creat node using malloc
    w=getnodo();
    clrscr();
    if(!w)
    {
    gotoxy(15,14);
    printf("Cant create new node");
    getch();
    }
    else
    {
    w->info=x;
    w->next=NULL;
    if(*plist==NULL)
    *plist=w;
    else
    {
    for(q=*plist;q->next!=NULL;q=q->next);
    q->next=w;
    }
    }
    }
    </code>

    as you can see i use a ** in the funcion (nodoaptr is apointer and i use nodoaptr *list) and then i only use the reference for the value of list, and works great, but if i change the prototype to void (nodoaptr list,int x) and use list instead of *list inside the function everytime the function ends the value of list is never changed, i can understand this if we were talking about regular variables but nodoaptr is a pointer itself, so why it doesnt change the value?, thanks so much in advanced.

    Juan Zamudio

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    4

    same message but with [code] sorry

    it wat the first time i use the [code] so i think the [ wast just an example because html tags are like this <tag> so here is the same message but with the right tags

    Hi all, i hope you can help me understand why this acts like this, im putting here just one function but if you want to see the full file is here http://www10.brinkster.com/jmzl666/nodes.txt (is a txt just rename it to .c). first of all im working with turbo c++ 3 (i know is old but i cant afford a new compiler) and windows xp pro, wel, the problem is that i have a structure like this
    Code:
    struct node{
       int info;
       struct node *next;
    };
    typedef struct node *nodoaptr;
    //decalre this inside the main
      nodoaptr p=NULL;
    I try to make a list using malloc, everything works fine but i have a question (silly if you want), as you see the nodoaptr type is a pointer, so i supose it can be modified enywhere, but it doesnt, here is the original function to create a node (basic version)

    Code:
    void insnodo(nodoaptr *plist,int x)
      {
        nodoaptr q,w;
        //creat node using malloc
        w=getnodo();
        clrscr();
        if(!w)
          {
            gotoxy(15,14);
            printf("Cant create new node");
            getch();
          }
         else
            {
              w->info=x;
              w->next=NULL;
              if(*plist==NULL)
                *plist=w;
              else
               {
                  for(q=*plist;q->next!=NULL;q=q->next);
                  q->next=w;
               }
            }
      }
    as you can see i use a ** in the funcion (nodoaptr is apointer and i use nodoaptr *list) and then i only use the reference for the value of list, and works great, but if i change the prototype to void (nodoaptr list,int x) and use list instead of *list inside the function everytime the function ends the value of list is never changed, i can understand this if we were talking about regular variables but nodoaptr is a pointer itself, so why it doesnt change the value?, thanks so much in advanced.

    Juan Zamudio

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  3. linked list inside array of structs- Syntax question
    By rasmith1955 in forum C Programming
    Replies: 14
    Last Post: 02-28-2005, 05:16 PM
  4. question about linklist
    By fj8283888 in forum C Programming
    Replies: 1
    Last Post: 04-14-2004, 07:13 AM
  5. Bi-Directional Linked Lists
    By Thantos in forum C Programming
    Replies: 6
    Last Post: 12-11-2003, 10:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21