I am new here. Here I was trying to write a program to copy one file to another.
This program takes two filenames on the command line. e.g
#include <stdio.h>#include <stdlib.h>
int main(int argc, char *argv)
FILE *fp , *ft;
if ((fp = fopen(argv, "rb")) == NULL)
printf("Can't open %s for reading\n", argv);
if ((ft = fopen(argv, "wb")) == NULL)
printf("Can't open %s\n", argv);
while( (feof(fp) == 0) )
fread(&ch, sizeof(int),1, fp);
fwrite(&ch, sizeof(int),1, ft);
if (ferror(fp) != 0)
fprintf(stderr,"Error in reading file %s.\n", argv);
if (ferror(ft) != 0)
fprintf(stderr,"Error in writing file %s.\n", argv);
So it should copy test1 to test2. Now I created test1 in gedit. I just put one character "c" in it and closed it. And I ran the program. When I check sizes of test1 and test2 , using command, I see that test2 has 4 bytes and test1 has 2 bytes.
So something strange is happening here. I just put a single character in test1, so shouldn't it show 1 byte ? And why test2 is showing 4 bytes ? Any help appreciated. I have Win XP on my laptop. And I use Ubuntu 12 inside VirtualBox. So this is Linux environment...