This one supports binary strings of arbitrary lengths, but of course has many deficiencies, esp. when considering reading back from file. :) Should be good enough for a starter, though.
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
char A[]="111100000000111111";
int main() {
unsigned int slen = strlen(A);
unsigned int len = slen/8 + !!(slen%8);
unsigned char * str = malloc(len);
unsigned int i;
for (i = 0; i < slen; i++) {
if (!(i%8))
str[i/8] = 0;
str[i/8] = (str[i/8]<<1) | (A[i] == '1' ? 1 : 0);
}
if (slen%8)
str[len-1] <<= (8-slen%8);
int f = open("test.bin", O_CREAT | O_TRUNC | O_WRONLY, S_IRWXU);
write(f, str, len);
close(f);
};