Sunday, 15 July 2012

c - to read and write contents to a tar.gz file in linux -


I am trying to open a tar.gz file and read the content of that file in buffer. I want to create another tar.gz file and write buffer in a newly created tarf file. Will the new file be similar to the previous one? The code is as follows:

  int main () {FILE * fp, * fp1; Int lane, lane 1; Int length = 0; Four * buf = maulok (1024); Four * buf1 = maulok (1024); Fp = fopen ("/ home / sharwari / download / criu-1.4 / 3049.tar.gz", "rb"); Ftp1 = fopen ("/ home / sharwari / imp5.tgz"); (print ("% s", buf);} Fclose (fpose); FP1 = fopen ("lane = fred (buff, 1024,1, fp)" gt; "West Bengal"); if (fp1 == NULL) printf ("\ n \ Terror in file ..."); len1 = fwrite (buf, 1, strlen (buf), fp1); printf ("\ n \ T Number of written bytes:% d ", len1); fclose (FP1);}  

You have the right idea but there are many problems in your code at least:

  1. While the loop will eliminate all but the last 1024 bytes because you read 1024 bytes Live and b You can not use the stringin on binary data.
  2. More error checking on the Fred is required to determine whether you have Successfully read all of the files or have an error or not. Read the Fried Man Page (this will point you to Fever and Panic).
  3. This is a good practice to free any Maulocode memory .

No comments:

Post a Comment