Created
April 7, 2022 19:04
-
-
Save tomioe/28b5205aab3510020c4577149d593b20 to your computer and use it in GitHub Desktop.
Struct Test
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 <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