1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2016
    Rep Power

    Register in C - ADT

    Good morning to all

    I wish make a data register in Abstract Data Type(ADT) , where there are a main.c, a StrCol.c and
    a StrCol.h(header) files. Among the data I wanna register are : name, a list of phone numbers and a
    list of e-mails type StrCol. In this way I intend to insert in the list and to list data referring to a contact.

    I've created a variable named as BLOCK to define size of each block on memory and a MAX variable
    to inform the maximum quantity of blocks it should have. Following this thought, when you try to insert
    a data in list , it is first verified if a contact exists and if the blocks are filled. If there's no contact it is
    allocated on memory a pointer array(type char) where each one of them will point to a memory block,
    according to data size user is entering. If there's a contact and if blocks were already filled and not
    exceed the maximum block numbers, so it is done a memory reallocation, where it is available a new
    block without loosing old data. I've created in the StrCol.h file , a StrcCol struct where inside it I have
    named list pointer of pointer variable. But some information are mismatched because I had already
    defined BLOCK and COUNTER fields inside StrCol.h file , but I don't know how to call that in the
    StrCol.c file.

    I am very confused and I'm finding it very difficult on how to create a contact list inside main.c function
    and how to list data like name, phone list and email list from each contact . Any help will be very appreciated .
    Thanks in advance.

    ==================Inside main.c=====================
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "StrCol.c"
    struct contact
      char name[50];
      StrCol phones;
      StrCol emails;
    int main(void)
        struct contact c1;
    ===================Inside StrCol.c===================
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "StrCol.h"
    #define BLOCK 4
    #define MAX 2
    int counter = 0;
    int block_nums = 0;
    //Create a generic list adapted to insert phone and emails.
    void insert(StrCol *l , char *s)
       if((counter != 0) && (counter % BLOCK == 0 ))
          if(block_nums >= MAX )
              printf("Full Schedule!\n");
          l->list = (char**) realloc(l->list ,(blocks_nums + 1) * BLOCK *
          l->list = (char**) malloc (BLOCK * sizeof(char*));
          l->list[counter] = (char*) malloc(strlen(s) * sizeof(char));
    void list(StrCol *l)
    ====================Inside StrCol.h==================
    typedef struct _col
      int BLOCK ;
      int COUNTER ;
      char **list;
    void insert(StrCol *l , char *s);
    void list(StrCol *l);
    #endif // STRCOL_H_INCLUDED
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    S.E. Washington state
    Rep Power
    There are many errors in your code.
    main() doesn't return a value
    in main() you only have a struct declared that has already been initialized followed by c1 which is not declared or initialized.
    You aren't telling the program to do anything but you are not letting it end either.

IMN logo majestic logo threadwatch logo seochat tools logo