I need to do a program in c to copy the content of a file in another file. I'm using HANDLE
objects to open the source and destination file and I'm using DWORD
to read the content. The code is as follows
HANDLE hIn = CreateFile("testSource.txt", FILE_READ_DATA, 0 , NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE hOut = CreateFile("testTarget.txt", FILE_WRITE_DATA, 0 , NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
char buf[30] = {'HANDLE hIn = CreateFile("testSource.txt", FILE_READ_DATA, 0 , NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE hOut = CreateFile("testTarget.txt", FILE_WRITE_DATA, 0 , NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
char buf[30] = {'%pre%'};
if(hIn == INVALID_HANDLE_VALUE || hOut == INVALID_HANDLE_VALUE)
{
printf("No existe alguno de los archivos\n");
} else
{
DWORD readText;
ReadFile(hIn, buf, 36, &readText, NULL);
WriteFile(hOut, buf, 36, &readText, NULL);
}
CloseHandle(hIn);
CloseHandle(hOut);
'};
if(hIn == INVALID_HANDLE_VALUE || hOut == INVALID_HANDLE_VALUE)
{
printf("No existe alguno de los archivos\n");
} else
{
DWORD readText;
ReadFile(hIn, buf, 36, &readText, NULL);
WriteFile(hOut, buf, 36, &readText, NULL);
}
CloseHandle(hIn);
CloseHandle(hOut);
The problem is that the functions ReadFile
and WriteFile
need to have the size that you want to read or that you want to write. How can I obtain the number of characters contained in the HANDLE
object of the file I wrote so that I can indicate how many characters I am going to write in the destination file?