Ionic compounds are those which are formed by either losing or gaining electrons completely .
Now carbon is at the borderline, basically it has a choice whether 1. it wants to gain 4 electrons or 2. lose the same in order ro acquire noble gas configuration.
1st case In the former case its small nucleus wont be able to handle 4 more electrons i.e 10.
2nd case Since we know energy is always required to knock out an electron from an element (Like always ;)) , the sum of four ionisation enthalpies (energy required to knock out the most loosely bound electron from a gaseous atom) would be very high.
And therefore carbon chooses none of them and decides to share its electrons to complete its octet and hence follows octet rule.