Charging of dust particles in comets and in interplanetary space