Crystal energy functions via the charge in types A and C