We've been assigned an ASCII compression project for Systems Programming, and I'm having a hard time with one specific line in my code.
I asked a question about compressing, and I adapted the array code to my program after working through the first dozen letters of a sample file on paper. In ddd, the values of the packed[]
array are what I worked out on paper, but the values aren't being written to the file.
unsigned char packed[7]; //compression storage
int i, jCount;
int j;
int bufferLength= sizeof(unpacked)/sizeof(char);
//loop through the buffer array
for (i=0; i< bufferLength-1; i++){
j= i%7;
jCount++;
//fill up the compressed array
packed[i]= packer(unpacked[i], unpacked[i+1], j);
//compressed array is full, write to file, then clear
if ((j%7==6) && (j > 1)){
int writeLoop;
for (writeLoop=0; writeLoop < 8; writeLoop++){
//printf("%X", packed[writeLoop]); //write to screen
write(openWriteFile, &packed[writeLoop], 1);//this is my trouble, write to file
}
memset(&packed[0], 0, sizeof(packed)); //clear array
}
//more code down here for padding the end of short bytes.
The write function expects a const void *
as the second argument, which is why I'm referencing the value of that particular array slot, but nothing is written to the file.
When I delete the &, I get a compile warning.
Any suggestions to get me down the right path are appreciated.