You have not allocated space for messages (based on what you have posted). You either need to allocate space (malloc function) or declare a character array before using.
For example:
char messages[3];
fgets(messages,3,stdin);
or
char *messages;
/* ask for memory */
*message = malloc(3);
fgets(messages,3,stdin);
/* do some processing */
/* release the memory back */
free(messages);