// answer to task 4 of assignment 6

#include <stdio.h>

// first mistake: to use malloc, we must include stdlib.h
#include <stdlib.h> // correction

int main()
{
  // second mistake: the length of memory allocated should be 6 characters,
  // not 5.
  //char * my_string = (char *) malloc(sizeof(char) * 5);
  char * my_string = (char *) malloc(sizeof(char) * 6); // correction

  my_string[0] = 'h';
  my_string[1] = 'e';
  my_string[2] = 'l';
  my_string[3] = 'l';
  my_string[4] = 'o';

  // third mistake: we should put the null character at position 5.
  my_string[5] = 0; // correction.
  
  printf("my_string = %s\n", my_string);

  // fourth mistake: we should free my_string at the end
  free(my_string); // correction
}
