Skip to content

Commit

Permalink
adding 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfosse committed Mar 24, 2017
1 parent 35b5cf6 commit 3c4747a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
34 changes: 34 additions & 0 deletions 0x11-singly_linked_lists/0-main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "lists.h"

/**
* main - check the code for Holberton School students.
*
* Return: Always 0.
*/
int main(void)
{
list_t *head;
list_t *new;
list_t hello = {"World", 5, NULL};
size_t n;

head = &hello;
new = malloc(sizeof(list_t));
if (new == NULL)
{
printf("Error\n");
return (1);
}
new->str = strdup("Hello");
new->len = 5;
new->next = head;
head = new;
n = print_list(head);
printf("-> %lu elements\n", n);
free(new->str);
free(new);
return (0);
}
15 changes: 15 additions & 0 deletions 0x11-singly_linked_lists/0-print_list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "lists.h"
/**
* print_list - prints all elements in a list_t list.
* @h: list to be printed.
* Return: Number of nodes.
*/
size_t print_list(const list_t *h)
{
int i;

for (i = 0; h != (NULL); h = h->next, i++)
printf("[%d] %s\n", h->len, h->str);

return (i);
}
Binary file added 0x11-singly_linked_lists/a
Binary file not shown.
3 changes: 3 additions & 0 deletions 0x11-singly_linked_lists/lists.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#ifndef LIST_H
#define LIST_H
#include <stdio.h>
#include <stdlib.h>
#include "lists.h"
/**
* struct list_s - singly linked list
* @str: string - (malloc'ed string)
Expand Down

0 comments on commit 3c4747a

Please sign in to comment.