Here is your function rewritten so the looping is a little clearer (at least to me it is) :
while(1)
{
int i = 0;
monitor.length = read(monitor.fd, monitor.buffer, BUFFER_LEN);
while(i<monitor.length)
{
struct inotify_event *event = (struct inotify_event *)&monitor.buffer[i];
if(event->len)
{
if(event->mask & *maskPtr)
{
if(event->mask & IN_ISDIR)
{
printf("Directory is created\n");
break;
}
else
{
printf("File is created\n");
break;
}
}
}
}
}
The break will cause execution to jump out of the inner loop but not out of the outer while loop. If you run this code in a debugger you will find the code calling read again after the printf is called.