Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define NMAX 100
- typedef struct {
- int id;
- char name[NMAX];
- } Entity;
- Entity cloneEntity(const Entity *const ep) {
- Entity aux;
- aux.id = ep->id;
- strncpy(aux.name, ep->name, NMAX);
- return aux;
- }
- void printEntity(const Entity *const ep) {
- printf("{ id: %d, name: %s }\n", ep->id, ep->name);
- }
- int main(void) {
- Entity e1 = {.id = 1, .name = "asd"}, e2;
- e2 = cloneEntity(&e1);
- strcat(e2.name, "123");
- printEntity(&e1);
- printEntity(&e2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement