Extension of the C method to nonhomogeneous media: application to nonhomogeneous layers with parallel modulated faces and to inclined lamellar gratings