fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct
  4. {
  5. char *da;
  6. unsigned long long int x;
  7. }t_1Dc;
  8.  
  9. void destroy_1D_c( t_1Dc *s)
  10. {
  11. deallocate_1D_c(s->da); free(s); s=NULL;
  12. }
  13.  
  14. void deallocate_1D_c( char *p )
  15. {
  16. if (p)
  17. free(p), p=NULL;
  18.  
  19. else printf("deallocate.h::deallocate_1D_c\n");
  20. }
  21.  
  22. char *allocate_1D_c( unsigned long long int n )
  23. {
  24. unsigned long long int i;
  25. char *p = NULL;
  26. if ((p = (char *)malloc(n*sizeof(char))))
  27. for ( i=0 ; i<n ; i++ )
  28. p[i]='\0';
  29.  
  30. else printf("allocate.h::allocate_1D_c\n");
  31.  
  32. return p;
  33. }
  34.  
  35. t_1Dc *create_1D_c( unsigned long long int x )
  36. {
  37. t_1Dc *s = NULL;
  38. if ( (s = (t_1Dc*)malloc(sizeof(t_1Dc))) )
  39. {
  40. if ((s->da = allocate_1D_c(x)))
  41. s->x = x;
  42.  
  43. else printf("create_da.h::create_1D_c\n");
  44. }
  45. else printf("create_da.h::create_1D_c\n");
  46. return s;
  47. }
  48.  
  49. int main(){
  50. t_1Dc* t = create_1D_c(5);
  51. destroy_1D_c(t);
  52. return 0;
  53. }
Success #stdin #stdout 0s 1916KB
stdin
Standard input is empty
stdout
Standard output is empty