#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <sys/types.h>
#include <dirent.h>
#include <ctype.h>
#include <string.h>
int main (int argc, char* argv[])
{
int temp;
char* source = argv[1]; //dereferencing possible invalid arguments
char* dest = argv[2];
FILE* src;
FILE* dst;
src = fopen (source, "w"); //open for write, but intend to read
dst = fopen (dest, "w");
while (src && dst) //¿why while?
{
if (3 != argc) //this is too late, you already tried to open the files
{
printf ("Your Argument should look like :");
printf ("./simple_cp.c Source Destination\n");
return EXIT_FAILURE;
}
elseif (NULL == src || NULL == dst) //already check on line 20
{
printf ("Konnte Source/Dest. Datei nicht öffnen!\n");
return EXIT_FAILURE;
}
while (EOF != fgetc (src)) //extract one character
{
temp = fgetc (src); //extract another character
fprintf (dst, "%c", temp); //you are missing half of the characters
}
//close does not set to NULL, because of your while you'll attemp to read from invalid files
fclose (src);
fclose (dst);
}
return 0;
}
I m sorry that i dont familiar with the UC file operation,i wrote it in c++ fstream way;It does the same operation as yours;And it worked ,i tried;Hope this could help ;
Anything you dont understand,let me know;