The EDIBLES survey: VII. A survey of C2 and C3 in interstellar clouds