0x13. C More singly linked lists Task 07 - humtej1204/holbertonschool-low_level_programming GitHub Wiki
mandatory
Write a function that returns the nth node of a listint_t linked list.
- Prototype:
listint_t *get_nodeint_at_index(listint_t *head, unsigned int index);
- where
index
is the index of the node, starting at0
- if the node does not exist, return
NULL
julien@ubuntu:~/0x13. More singly linked lists$ cat 7-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;
listint_t *node;
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);
node = get_nodeint_at_index(head, 5);
printf("%d\n", node->n);
print_listint(head);
free_listint2(&head);
return (0);
}
julien@ubuntu:~/0x13. More singly linked lists$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 7-main.c 3-add_nodeint_end.c 0-print_listint.c 5-free_listint2.c 7-get_nodeint.c -o h
julien@ubuntu:~/0x13. More singly linked lists$ ./h
0
1
2
3
4
98
402
1024
98
0
1
2
3
4
98
402
1024
julien@ubuntu:~/0x13. More singly linked lists$
- GitHub repository: holbertonschool-low_level_programming
- Directory: 0x13-more_singly_linked_lists
- File: 7-get_nodeint.c