/* Allocate.c */
#include <stdio.h>
#include <string.h>

struct chemical_element
  {
    char element_name[20];
    double atomic_weight;
  };

int main()
{
  struct chemical_element *my_ptr;  /* Declare pointer to point to the */
                                    /* dynamically-allocated structure. */
  /* Allocate memory for structure. */
  my_ptr = (struct chemical_element *)malloc(sizeof(struct chemical_element));

  if(my_ptr != NULL)  /* Check to make sure allocation was successful. */
   {
    /* Initialize members of the structure. */
    strcpy(my_ptr->element_name, "Nitrogen");
    my_ptr->atomic_weight = 14.0067;
    
    /* Display members of the dynamically-allocated structure. */
    printf("Element Name: %s\n", my_ptr->element_name); 
    printf("Atomic Weight: %.4lf\n", my_ptr->atomic_weight);

    free( my_ptr);  /* Free memory used by the data. */
   }
  else
   {
    printf("Memory allocation was unsuccessful.\n");
   }
  return 0;
}

