如何用C调用windowsAPI将一个文件的前512个字节写到一个.img中
rt,这是我们的作业,要用四种方法,先问问一个,剩下的三个应该会比较类似
求大神帮帮忙……
[解决办法]
4个方法
:
1.
HANDLE WINAPI CreateFile( __in LPCTSTR lpFileName, __in DWORD dwDesiredAccess, __in DWORD dwShareMode, __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes, __in DWORD dwCreationDisposition, __in DWORD dwFlagsAndAttributes, __in_opt HANDLE hTemplateFile);
[解决办法]
#include <stdio.h>#include <sys/stat.h>#include <sys/types.h>#include <fcntl.h>int main(void){ int fdin, fdout; int n; char buf[512] = {0}; fdin = open("c_ghost", O_RDONLY); if(fdin < 0) { perror(""); exit(1); } fdout = open("floppy.img", O_WRONLY | O_CREAT); if(fdout < 0) { perror(""); exit(1); } if((n = read(fdin, buf, 512)) < 512) { printf("c_ghost is %d bytes, smaller than 512 bytes.\n", n); exit(1); } write(fdout, buf, 512); close(fdout); close(fdin); return 0;}