Let the number of marbles Charlie has initially be C and David, D. C/D=2/7, so D=7C/2. Let x be the number of marbles David gives Charles, so David has D-x=7C/2-x and Charles has C+x. So 7C/2-x=2(C+x). C+x=24, so 7C/2-x=48, therefore 7C-2x=96. But C=24-x, so 168-7x-2x=96, and 9x=168-96=72, making x=8. Therefore, David gave 8 marbles to Charles.
Check: C=24-8=16 and D=7*16/2=56. David gives 8 marbles to Charles leaving 48 and Charles has 24, half as many as David. OK!