📄 copyfile.c
字号:
#include <windows.h>
#include <stdio.h>
int main()
{
HANDLE hFile;
HANDLE hTempFile;
DWORD dwBytesRead, dwBytesWritten, dwPos;
char szTempName[MAX_PATH];
char buffer[4096];
// Open the existing file.
hFile = CreateFile("ORIGINAL.TXT", // file name
GENERIC_READ, // open for reading
0, // do not share
NULL, // no security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (hFile == INVALID_HANDLE_VALUE)
{
printf("%c","Could not open file."); // process error
}
// Create a temporary file.
GetTempFileName("\\TEMP", // dir. for temp. files
"NEW", // temp. file name prefix
0, // create unique name
szTempName); // buffer for name
hTempFile = CreateFile((LPTSTR) szTempName, // file name
GENERIC_READ | GENERIC_WRITE, // open for read/write
0, // do not share
NULL, // no security
CREATE_ALWAYS, // overwrite existing file
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (hTempFile == INVALID_HANDLE_VALUE)
{
printf("%c","Could not open file."); // process error
}
// Read 4K blocks to the buffer.
// Change all characters in the buffer to uppercase.
// Write the buffer to the temporary file.
do
{
if (ReadFile(hFile, buffer, 4096,
&dwBytesRead, NULL))
{
CharUpperBuff(buffer, dwBytesRead);
WriteFile(hTempFile, buffer, dwBytesRead,
&dwBytesWritten, NULL);
}
} while (dwBytesRead == 4096);
// Close both files.
CloseHandle(hFile);
CloseHandle(hTempFile);
// Move the temporary file to the new text file.
if (!MoveFile(szTempName, "ALLCAPS.TXT"))
{
printf("%c","Could not open file."); // process error
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -