Take a look at this example of using CreateFile / ReadFile:
Creating and Using a Temporary File[
^]:
hTempFile = CreateFile((LPTSTR) szTempFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hTempFile == INVALID_HANDLE_VALUE)
{
PrintError(TEXT("Second CreateFile failed"));
if (!CloseHandle(hFile))
{
PrintError(TEXT("CloseHandle(hFile) failed"));
return (7);
}
return (4);
}
do
{
if (ReadFile(hFile, chBuffer, BUFSIZE, &dwBytesRead, NULL))
{
CharUpperBuffA(chBuffer, dwBytesRead);
fSuccess = WriteFile(hTempFile,
chBuffer,
dwBytesRead,
&dwBytesWritten,
NULL);
if (!fSuccess)
{
PrintError(TEXT("WriteFile failed"));
return (5);
}
}
else
{
PrintError(TEXT("ReadFile failed"));
return (6);
}
} while (dwBytesRead == BUFSIZE);
if (!CloseHandle(hFile))
{
PrintError(TEXT("CloseHandle(hFile) failed"));
return (7);
}
Quote:
And to further improve my program how can i create variables in a loop which i can use later in the program?
You need to define the variables
out of loop in order to use them later in the program.