Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   binary File Q.? (http://www.go4expert.com/forums/binary-file-q-t21040/)

hanann 18Feb2010 23:34

binary File Q.?
 
if i want to read abinary file and copy it to another one using fwrite and fread

that i will passing an integer and arry of string then open file in it,s mode

my Qu. is how can i do it to open any kind of file like vedio or exe file can i copy and store them
using C languge and what this idea need ?

the second Q. is should i know the size of byets that i want to copy

help me with your answer

ungalnanban 19Feb2010 10:19

Re: binary File Q.?
 
you can read the text file using fread and you can write the content using fwrite.

the read and write system calls are allowed only for files. it will never read a special files. like directory , socket, FIFO,

if you want to read a directory you can use opendir.

you can specify the buffer size in read and write. if you cant to read single character or single line at a file.




:cuss::cuss:

virxen 19Feb2010 13:04

Re: binary File Q.?
 
is this what you are looking for?

Code:

#include <stdio.h>


/* Main program */

int main (int argc, char * argv[])
{
  FILE * fin, * fout;
  unsigned char buffer[1000];
  size_t count;

  fin = fopen(argv[1], "rb");
  if (fin == NULL)
      return 1;

  fout = fopen(argv[2], "wb");
  if (fout == NULL)
      return 2;
     
  while (!feof(fin)) {
      count = fread(buffer, 1, 1000, fin);
      fwrite(buffer, 1, count, fout);
  }

  fclose(fin);
  fclose(fout);

  return 0;
}



All times are GMT +5.5. The time now is 06:03.