title: create a tar.gz file using C
body: <p>Hello guys i want to create tar.gz file  from a c 
  program</p>
  
  <p>I tried <code>system("tar -zcvf file.tar.gz file")</code> but it didn't work. Is there any better alternative you could do. This is my code</p>
  
  <pre><code>int make_tar() {
      char buff[100];
      DIR *d;
      struct dirent *dir;
      d = opendir(".");
  
      if (d) {
          while ((dir = readdir(d)) != NULL) {
            if (dir-&gt;d_type == DT_REG) {
               sprintf(buff,"%s",dir-&gt;d_name);
               system("tar -zxvf buff.tar.xz buff");
           }
      }
      closedir(d);
  
      return(0);
  }
  </code></pre>