Skip to content

Commit

Permalink
Added Example
Browse files Browse the repository at this point in the history
Added example.c file with usage example, also added imports to list.h
 example.c: A simple example on how to use the header
 list.h: Added imports that I forgot to add before
  • Loading branch information
yuriKhordal committed Feb 15, 2021
1 parent 44047be commit 440f429
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<stdio.h>
#include "list.h"

STRUCT_LIST(int, ListInt)

int main(int argc, char* argv){
ListInt* list = ListInt_new();

int next = 1;
//loop until user enters 0 or something that isn't a number
printf("Enter numbers(0 to finish): ");
while (next) {
if (scanf(" %d", &next) != 1) break;
ListInt_add(list, next);
}

printf("List: ");
for (int i = 0; i < ListInt_size(list); i++){
printf("%d ", ListInt_get(list, i));
}
printf("\n");

return 0;
}
4 changes: 4 additions & 0 deletions list.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef __LIST_H__
#define __LIST_H__

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define DEFAULT_SIZE 8

#define STRUCT_LIST(type, List_name) \
Expand Down

0 comments on commit 440f429

Please sign in to comment.