title: What header variables do I need to use to extract a tar file
body: <p>I intend to do a C program that extracts a <code>.tar</code> archive. I'm currently using <code>Debian</code> from my Windows Terminal, and code using the Windows Version of <code>Visual Studio Code</code>.</p>
  <p>As far as I know, tar files contain a <code>header</code> block (of 512 bytes) and the block with all the <code>content</code> of the certain file (also of 512 bytes).</p>
  <p>From <a href="https://en.wikipedia.org/wiki/Tar_(computing)" rel="nofollow noreferrer">Wikipedia</a>, I found out that the <code>header</code> contains loads of variables that contain the name of the certain file, its mode, the name of the user that archived the tar file, and so on.</p>
  <p>Based on what Wikipedia has taught me, I'm using two structs: one for the header of the certain file, and one for its content (...)</p>
  <pre><code>typedef struct tarHeaderBody {
      char fname[100];
      char file_mode[8];
      char owner_numeric_userid[8];
      char group_numeric_userid[8];
      char file_size[12];
      char last_modification_time[12];
      char checksum[8];
      char link_indicator;
      char linkedfname[100];
      char severalFields[156];
      char typeFlag;
      char sameField[100];
      char ustarIndicator[6];
      char ustartVer[2];
      char ownerUserName[32];
      char ownerGroupName[32];
      char deviceMajorNo[8];
      char deviceMinorNo[8];
      char fnameprefix[155];
  } tarHeader;
  
  typedef struct tarContentBody {
      char content[512];
  } tarContent;
  </code></pre>
  <p>(...) declared in the main function as:</p>
  <pre><code>tarHeader t;
  tarContent tContent;
  </code></pre>
  <p>I'm using <code>fopen()</code> and <code>fread()</code> using the first struct to read the contents of the header:</p>
  <pre><code>FILE *f = fopen(&quot;output.tar&quot;, &quot;rb&quot;)
  fread(&amp;t, sizeof(t), 1, f);
  </code></pre>
  <p>The file is read correctly. I'm also trying to output every variable from the struct, and starting from <code>t.severalFields</code>, variables are outputted &quot;weird&quot;. Also, the content of the archived text file is outputted somewhere in these header variables.</p>
  <p>I'm pretty sure the issue is with the organizing of the header variables, especially with the <code>t.severalFields</code> variable, as I should declare more variables that contain the info from there. The problem is, I don't find any website or source of information that may help me in doing so. I don't know what variables or info `t.severalFields' contains.</p>
  <p>Also, named the variable <code>severalFields</code> because in the first row from the third table from the Wikipedia link mentioned above, there lays written:</p>
  <blockquote>
  <p>0 156 (Several fields, same as in the old format)</p>
  </blockquote>
  <p>meaning that it is a variable with a size of 156 bytes.</p>
  <p>So, my final question is: what variables should my <code>tarHeaderBody</code> struct contain? Do I need all of them if I want to extract the files? Or are the name of the file and its content (which doesn't lay in the header) enough? Thank you so much.</p>
  <p>Also, if you need more snippets of the code, I can provide them to you.</p>