-
-
Save lsoares/8a729be3d8411686e911bdbc940f1704 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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