Thread: Adding arrays of integers in a node struct

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    5

    Adding arrays of integers in a node struct

    Hi I am just wondering HOW TO INSERT AN ARRAY IN THIS node struct in C programming
    ---------------------------------------------------------------------------

    typedef struct node *node_ptr ;

    struct node
    {

    char *Deptname;
    int Max_People;
    int List_of_IDS[100];
    node_ptr next;
    };

    This node struct adds the department name and then adds their IDs for future record?. I am just wondering how to add an array of List_of_IDs[100] for a particular department?.
    Range of List_of_IDS[] is List_of_IDS[0] to List_of_IDS[Max_people-1] . Please this is urgent !!!!! Just give me a good reply. Thanks

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    I do not fully understand your question. Don't you mean how to fill the array instead of inserting an array?

    In that case:

    Code:
    struct node entry;
    
    for (index = 0; index < Max_people-1; index++)
    {
      entry.List_of_IDS [index] = value;
    }

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    5

    Here is the detailed version

    The character thing in the struct node is the part of the linked list, and in that same struct there is IDs array.

    Now we have to search for that node in the linked list , and then add the integer in the IDs array.

    Please reply ASAP

    Thanks a lot

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    So the problem is searching in a linked list?

    Code:
    list_ptr = linked_list;
    found = FALSE;
    
    while (list_ptr != NULL && found == FALSE)
    {
      if (strcmp (list_ptr->data, data_to_search_for) == 0)
      {
        found = TRUE;
      }
      else
      {
        list_ptr = list_ptr->next;
      }
    }

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    5

    and then you have to add the array inside that found character

    Thanks for such a quick reply ....

    Then,

    You have to insert the int ID inside the array in the same node??

    So basically the program is like this ..

    Enter the character name where you want to put you ID in:

    You typed: abc

    /* It searches for that name and asks you to enter an int ID */

    This integer ID is stored in that array in that node where that character is....

    Thanks again for a quick reply.. I am desperate at the moment. please reply
    Cheers

  6. #6
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    If the node is found, then list_ptr points to the node which needs to be updated. To update the array you would have to do something like this:

    list_ptr->List_of_IDS [index] = value;

  7. #7
    Registered User
    Join Date
    Apr 2003
    Posts
    5

    This is the problem.... Sorry about before

    Can you tell me how to add an array of numbers in this struct node?


    typedef struct node *node_ptr;

    struct node {
    char *Dept_name;
    int dept_IDS[1000];
    node_ptr next;
    }

    So basically the program is like this ..

    Enter the character name where you want to put you ID in:

    You typed: abc

    /* It searches for that name in the linked list (which is Dept_Name) and asks you to enter an int ID */

    This integer ID is stored in that array in that node where that Dept_Name is....



    How to add an integer inside the array of dept_IDS [] for a particular department name? And also we are working on a linked list


    Please reply ASAP!!!!
    Cheers

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>How to add an integer inside the array of dept_IDS [] for a particular department name?<<
    Search the list to find the desired node. Shiro has shown you how to do that already. Then do something like:

    >>NodePtr->dept_IDS[Index] = 10;
    where Index is the element number of the array you want to assign the value 10 to.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Concatenating in linked list
    By drater in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 11:10 PM
  2. Memory Leak
    By jtullo in forum C Programming
    Replies: 7
    Last Post: 12-11-2006, 11:45 PM
  3. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  4. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  5. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM