Note that there are some explanatory texts on larger screens.

plurals
  1. POSegmentation fault in reading a .dat file
    primarykey
    data
    text
    <p>Right now, I'm working on an example code that I wish to integrate into my program later. What essentially I'm trying to do is read a .dat file byte by byte and interpret the data (ie. interpret boot sector to output the sector size, reserved sectors etc.)</p> <p>To do this, I am reading the data byte by byte and, using the descriptions in fat12 of <a href="https://www.win.tue.nl/~aeb/linux/fs/fat/fat-1.html#ss1.3" rel="nofollow">https://www.win.tue.nl/~aeb/linux/fs/fat/fat-1.html#ss1.3</a> , I translate the data into the information that I want. Right now, I can pull individual bytes from the file (Is it right to assume that the data pulled is in hex?). However, I need two bytes to have something meaningful. So, I need to combine two bytes into one, convert the hex data into decimal and output the information. Unfortunately, right now, I'm getting a seg fault and for the life of me, I can't figure out what's wrong. Thanks in advance!</p> <p>int main (int argc, char **argv){</p> <pre><code>FILE *fp ,*fptest; long lSize; char *buffer; //Open file fptest= open("fat_volume.dat", "rb"); //Read file into buffer fread(buffer,1,512,fptest); //Parse the boot sector char tmpA, tmpB; tmpA = buffer[10]; //First byte tmpB = buffer[11]; //Second byte //Combine the two bytes into one char combinedBytes[3]; strcpy (combinedBytes, tmpA); strcat (combinedBytes, tmpB); //Hex to decimal converter long int li1; li1 = strtol (combinedBytes,NULL,16); printf ("The sector size is: %ld.\n", li1); return 0; </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload