>my question is how do i pass buffer in DiskOpen to DumpSector ( unsigned char *buffer )?
Code:
DumpSector(&buffer);
Since, DumpSector() expects a pointer to a variable and not the value itself.
>how do i initialize members of Disk
Disk is not an instance, it's a datatype. You need to initialize it's Instance. 'theDisk' is a pointer to a type Disk, you need to allocate memory to this before you can use this, so:
Code:
theDisk = malloc(sizeof(Disk));
if(theDisk == NULL) {
perror(" malloc");
exit(-1);
}
To allocate memory to it's members:
Code:
theDisk->Jump = malloc(20);
if(theDisk->Jump == NULL) {
perror(" malloc");
exit(-1);
}
theDisk->Manufacturer = malloc(20);
if(theDisk->Manufacturer == NULL) {
perror(" malloc");
exit(-1);
}
/* ... */
strcpy(theDisk->Jump, "Here");
strcpy(theDisk->Manufacturer, "ABC");
printf(" %s %s\n", theDisk->Jump, theDisk->Manufacturer);
free(theDisk->Jump);
free(theDisk->Manufacturer);
free(theDisk);
>how do i close file?
How did you open it? If you opened the file with fopen(), use fclose() and if you opened with open(), use close() to close the file.
>i do not know how to pass fd in DiskOpen to DiskClose.
Add another parameter to the function DiskClose()
Code:
DiskClose(Disk *theDisk, int fd)
and from DiskOpen()
Code:
DiskOpen(theDisk, fd);
Also, check your code for error trapping, you haven't done any:
Code:
fd = open ("disk.img", O_RDONLY );
if(fd == -1) {
perror(" open");
exit(-1);
}
You haven't initialised 'buffer'