fork download
  1.  
  2. // dynamic memory allocate struct usage
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. typedef struct _account {
  8. char* name;
  9. char* birth;
  10. } account;
  11.  
  12. int main(int argc, char** argv)
  13. {
  14. account account_tmp;
  15.  
  16. account_tmp.name = strdup("linuxer");
  17. account_tmp.birth = strdup("1970.01.01");
  18.  
  19. printf("Sample output. name[%s], birth[%s]\n", account_tmp.name, account_tmp.birth);
  20.  
  21. free(account_tmp.name);
  22. free(account_tmp.birth);
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 2244KB
stdin
Standard input is empty
stdout
Sample output. name[linuxer], birth[1970.01.01]