I worked this one out. I needed to add a null character to indicate end of string.
C Programming outputting bytes into a file
Pergunta
I am trying to write a compression program, and the logic works fine when I print bits onto screen, however I am also trying to put these bits into a file. I do this by storing them into a char and outputting that char. This method works file for all characters other than things like space (0010 0000) or tabs (0000 1001). Is there some way of outputting a space or tab into a file?
void writeByte(char byte, FILE *comp){
fputc(byte,comp);
} //writing byte to file
void writeBit(int bit, FILE *comp){
if(ind >= 0){
byte|= (bit<<ind);
ind--;
}
else{
writeByte(byte,comp); //write byte to file
reset();
writeBit(bit,comp);
}
//printf("%d\n", bit);
} //storing bits in a byte
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow