itme86,
hello again, just encountered a error I am stuck on: -
--) When adding files to archive ( the first program), when we go back to write() the header data, we reserved 2 bytes(short) at beginning of file, two store value of how many files in archive.
like: write(fdout,(short*)&numfiles, sizeof(short)); - - at the time obviously variable 'numfiles' would have value ie say 4, representing no of files user added and thus that line above should have written say 4 into the first 2 bytes(short) at start of archive file, mistake me if I misunderstand?
--) So, in the second program (extracting) we have the line: -
Code:
int numfiles;
read(fdin, (short*)&numfiles, sizeof(short));
Obviously, the var 'numfiles' in this program would be zero intially and using the read() we want to read the value we stored in first 2 bytes of archive file, to get this value back out and put it back into var 'numfiles' correct me if I misunderstood?
-- ) The problem I have, I believe is either the numfiles value was not written into file in first place, or there is error with read() statement I using below, in my extract program : -
Code:
int numfiles; //would be empty obviously in this program until read value from file in
lseek(fdin, 0, SEEK_SET);
read(fdin, (short*)&numfiles, sizeof(short));
//want to check numfiles has number of files stored inside it
printf("%d is the number of files inside archive\n", numfiles);
printf("%x is the number of files inside archive- memory address\n", numfiles);
However, the memory address returns fine, but say I added one file to archive 'file1' then 'numfiles=1' should should it not, however it returns a number in its thousands like 23456 or something?
Is there a way I an see the header data to see if its written correctly, or is it always hidden?
What does (short*)&numfiles do, &numfiles is the memeory address of int numfiles variable, but what is (short*) about ?
Thanks
daza166