Skip to content

Instantly share code, notes, and snippets.

@tomioe
Created April 7, 2022 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomioe/28b5205aab3510020c4577149d593b20 to your computer and use it in GitHub Desktop.
Save tomioe/28b5205aab3510020c4577149d593b20 to your computer and use it in GitHub Desktop.
Struct Test
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int num;
void **elems;
} test_t;
void elem_append(test_t* test_str, void* elem_app) {
*test_str->elems = elem_app;
}
int main(int argc, char** argv) {
test_t* my_str = (test_t*) malloc(sizeof(test_t));
my_str->elems = malloc(sizeof(void*));
printf("Before: '%s'\n", *my_str->elems);
char* new_str = "I am the new element!";
elem_append(my_str, new_str);
printf("After '%s'\n", *my_str->elems);
return (EXIT_SUCCESS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment