detecting cycles in c