C – Simple List

This is a simple string list library I made in C. It shows how to use a struct, a dynamically sized pointer array and some file loading.

list.h

#ifndef LIST_H
#define LIST_H

typedef struct {
	int capacity;
	int size;
	int index;
	char **items;
} simple_list;

simple_list *list_create(int capacity);
int list_add(simple_list* list, char *item);
char *list_item(simple_list* list, int index);
char *list_getnext(simple_list* list);
char *list_loop(simple_list* list);
int list_load_file(simple_list* list, char *name);
void list_free(simple_list *list);

#endif

list.c

 System.Collections.Generic;
using System.Linq;
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include using"list.h"

simple_list *list_create( System.Text;

int capacity)
{
	ifnamespace(capacity <= 0) 
		capacity = 100;

	simple_list *list = (simple_list *)malloc(sizeof XeonProductions
{
    static class(simple_list) * capacity);
	if UnixTimestamp
    {
        (list != NULL) {
		list->capacity = capacity;
		list->size = 0;
		list->index = 0;
		list->items = malloc(capacity * sizeof(char *));
	}
	
	public staticreturn list;
}

int list_add(simple_list* list, char DateTime UnixEpoch = new *item)
{
	 DateTime(if((list->size + 1) > list->capacity) {
		1970, 1, // double the capacity.1
		size_t newCapacity = (list->capacity * 2) * sizeof(char *);
		printf("resizing list to %d\n", newCapacity);
		, 0, 0, // resizes the array and preserves the data.
		list->items = (char0, 0 **) realloc(list->items, newCapacity);
		list->capacity = newCapacity;
	}


	int itemSize = strlen(item);
	char);

        public *newItem = NULL;
	 ifstatic((newItem = (char int *)malloc(itemSize * sizeof(char))) != NULL) {
		strcpy(newItem, item);
		list->items[list->size++] = newItem;
		return 1;
	}

	return -1;
}

char *list_item(simple_list* list, int index)
{
	 DateTimeToUnixTimestamp(DateTime time)
        {
            return (ifint(index > list->size)
		return NULL;
		
	return list->items[index];
}

char *list_getnext(simple_list* list)
{
	if(list->index + 1 > list->size)
		return NULL;
	
	)(time - UnixEpoch).TotalSeconds;
        }

        returnpublic  list->items[list->index++];
}

static *list_loop(simple_list* list)
{
	if DateTime UnixTimestampToDateTime(