Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem solved (line 51)
- #include <stdio.h>
- #include <stdlib.h>
- #include <panel.h>
- #include <unistd.h>
- struct list
- {
- struct list *next;
- WINDOW *window;
- PANEL *panel;
- };
- static struct list *the_list;
- void add();
- void del();
- int count();
- int main()
- {
- initscr();
- the_list = malloc(sizeof(struct list));
- the_list->next = NULL;
- while(1)
- {
- for(int i = 0; i < 100; i++)
- {
- //usleep(20000); // Debug (to slow the output)
- add();
- printf("%d\n", count()); // Debug
- refresh();
- }
- for(int i = 0; i < 100; i++)
- {
- //usleep(20000);
- del();
- printf("%d\n", count());
- refresh();
- }
- }
- free(the_list);
- return 0;
- }
- void del()
- {
- struct list **list = &the_list;
- struct list *temp = the_list;
- delwin((*list)->window); //this one must not occur before
- del_panel((*list)->panel); // this one.
- *list = (*list)->next;
- free(temp);
- }
- void add()
- {
- struct list **list = &the_list;
- while((*list)->next != NULL)
- list = &(*list)->next;
- (*list)->next = malloc(sizeof(struct list));
- (*list)->next->next = NULL;
- (*list)->window = newwin(0,0,0,0);
- (*list)->panel = new_panel((*list)->window);
- }
- // Just for debug
- int count()
- {
- int nb = 0;
- struct list **list = &the_list;
- while((*list)->next != NULL)
- {
- list = &(*list)->next;
- nb++;
- }
- return nb;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement