0x13. C More singly linked lists Task 06 - humtej1204/holbertonschool-low_level_programming GitHub Wiki
mandatory
Write a function that deletes the head node of a listint_t linked list, and returns the head node’s data (n).
- Prototype:
int pop_listint(listint_t **head);
- if the linked list is empty return
0
julien@ubuntu:~/0x13. More singly linked lists$ cat 6-main.c
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "lists.h"
/**
* main - check the code
*
* Return: Always 0.
*/
int main(void)
{
listint_t *head;
int n;
head = NULL;
add_nodeint_end(&head, 0);
add_nodeint_end(&head, 1);
add_nodeint_end(&head, 2);
add_nodeint_end(&head, 3);
add_nodeint_end(&head, 4);
add_nodeint_end(&head, 98);
add_nodeint_end(&head, 402);
add_nodeint_end(&head, 1024);
print_listint(head);
n = pop_listint(&head);
printf("- %d\n", n);
print_listint(head);
n = pop_listint(&head);
printf("- %d\n", n);
print_listint(head);
free_listint2(&head);
printf("%p\n", (void *)head);
return (0);
}
julien@ubuntu:~/0x13. More singly linked lists$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 6-main.c 3-add_nodeint_end.c 0-print_listint.c 5-free_listint2.c 6-pop_listint.c -o g
julien@ubuntu:~/0x13. More singly linked lists$ valgrind ./g
==4369== Memcheck, a memory error detector
==4369== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==4369== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==4369== Command: ./g
==4369==
0
1
2
3
4
98
402
1024
- 0
1
2
3
4
98
402
1024
- 1
2
3
4
98
402
1024
(nil)
==4369==
==4369== HEAP SUMMARY:
==4369== in use at exit: 0 bytes in 0 blocks
==4369== total heap usage: 9 allocs, 9 frees, 1,152 bytes allocated
==4369==
==4369== All heap blocks were freed -- no leaks are possible
==4369==
==4369== For counts of detected and suppressed errors, rerun with: -v
==4369== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
julien@ubuntu:~/0x13. More singly linked lists$
- GitHub repository: holbertonschool-low_level_programming
- Directory: 0x13-more_singly_linked_lists
- File: 6-pop_listint.c