buf[20]はまずいだろ
char* buf;
for(i=0;;i++) {
 buf = malloc((int)(log(i)/log(10))+1);
 itoa(i,buf,2);
 printf("%s\n",buf);
 free(buf);
}