Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are reading into a buffer you never allocated memory for.</p> <p>What you're trying now is to read from some junk value in memory, who knows, which almost always leads to a segmentation fault.</p> <p>Use:</p> <pre><code>char *buffer = malloc(512 * sizeof(char)); // this allocates 512 times the size of a single char of memory </code></pre> <p>If you don't specify the number inside malloc to be of a specific size (e.g. malloc(512) the number is in bytes, though I think it's better to always include it.</p> <p>This specific error is called <a href="https://stackoverflow.com/questions/4007268/what-exactly-is-meant-by-de-referencing-a-null-pointer">dereferencing a null pointer</a></p> <p><strong>EDIT:</strong></p> <p>I've managed to run this code:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; int main (int argc, char **argv) { FILE *fp ,*fptest; long lSize; char *buffer; //Open file fptest = fopen("input.txt", "rb"); if (fptest == NULL) { printf("Error occurred when opening file"); return 1; } buffer = malloc(sizeof(char) * 512); //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, &amp;tmpA); strcat (combinedBytes, &amp;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>You also used a function <code>open()</code> which must be <code>fopen()</code>, and you need to pass the address of tmpA and tmpB to strcpy and strcat.</p> <p>This is why I don't understand why your compiler doesn't give any errors or warnings..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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