Skip to content

Instantly share code, notes, and snippets.

@lsoares
Last active May 15, 2024 22:57
Show Gist options
  • Save lsoares/8a729be3d8411686e911bdbc940f1704 to your computer and use it in GitHub Desktop.
Save lsoares/8a729be3d8411686e911bdbc940f1704 to your computer and use it in GitHub Desktop.
#include <string.h>
typedef struct {
char text[100];
} ToDoItem;
typedef struct {
ToDoItem list[100];
int size;
} ToDos;
void addToDoItem(ToDos *todos, const char *text) {
strcpy(todos->list[todos->size].text, text);
todos->size++;
}
#include <string.h>
#include <stdlib.h>
#include <assert.h>
typedef struct {
char text[100];
} ToDoItem;
typedef struct {
ToDoItem* list;
int size;
} ToDos;
void addToDoItem(ToDos *todos, const char *text) {
todos->list = realloc(todos->list, (todos->size + 1) * sizeof(ToDoItem));
assert(todos->list != NULL /* Memory allocation failed */);
strcpy(todos->list[todos->size].text, text);
todos->size++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment